首页 > 代码库 > JsRender系列demo(5) for else
JsRender系列demo(5) for else
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript" src="http://www.mamicode.com/scripts/jquery.js"></script> <script type="text/javascript" src="http://www.mamicode.com/scripts/jquery-ui.js"></script> <script type="text/javascript" src="http://www.mamicode.com/scripts/jsrender.js"></script> <link href="http://www.mamicode.com/scripts/demos.css" rel="stylesheet" /> <link href="http://www.mamicode.com/scripts/movielist.css" rel="stylesheet" /></head><body> <script id="movieTemplate" type="text/x-jsrender"> <tr> <td>{{:title}}</td> <td>{{for languages}} <div class="{{:#index%2 ? ‘even‘ : ‘odd‘}}"></div> <em>{{:name}}</em> {{else}} No alternate languages! {{/for}}</td> </tr> </script> <h2>Using {{for}} to render hierarchical data - inline nested template.</h2> <table> <thead> <tr> <th>title</th> <th>movieList</th> </tr> </thead> <tbody id="movieList"></tbody> </table> <script type="text/javascript"> var movies = [ { title: "Meet Joe Black", languages: [ { name: "English" }, { name: "French" } ] }, { title: "Eyes Wide Shut", languages: [ { name: "French" }, { name: "Mandarin" }, { name: "Spanish" } ] }, { title: "The Inheritance", languages: [ { name: "English" }, { name: "German" } ] }, { title: "Local Story", languages: [] }, { title: "My Home Video" } ]; $("#movieList").html($("#movieTemplate").render(movies)); </script></body></html>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。