handlebars使用DEMO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title>handlebars_v2.0_demo</title> <script type= "text/javascript" src= "js/jquery-1.8.2.min.js" ></script> <script type= "text/javascript" src= "js/handlebars-v2.0.0.js" ></script> </head> <div id= "demo" > </div> <script id= "user-template" type= "text/x-handlebars-template" > <h1>{{time}}</h1> {{ #each user}} <p> {{ #if name}} {{@index}}. 姓名:{{name}} 年龄:{{age}} 成年:{{Adult age}} {{ #Compare age 18 }} 大于等于18岁 {{ else }} 小于18岁 {{/Compare}} 记录时间:{{../../time}} {{/ if }} </p> {{/each}} </script> <script> $( function (){ var data = { user:[{ name: "sky" , age:28 },{ name: "json" , age:10 },{ age:2 },{ name: "joy" , age:18 }], time: "2014-12-26" } var myTemplate = Handlebars.compile($( "#user-template" ).html()); Handlebars.registerHelper( "Adult" , function (age){ return (age >= 18) ? "成年" : "未成年" ;}); Handlebars.registerHelper( "Compare" , function (i1,i2,options){ if (i1>=i2) { return options.fn( this ); } else { return options.inverse( this );}}); $( "#demo" ).html(myTemplate(data)); }) </script> <div id= "demo2" > </div> <script id= "class-template" type= "text/x-handlebars-template" > {{ #each this}} <dl> <dt>{{ class }} 共有{{group.count}}个小组 班长:{{student.[0].name}}</dt> {{ #with student}} {{ #each this}} <dd>{{name}}</dd> {{/each}} {{/ with }} </dl> {{/each}} </script> <script> $( function (){ var data2 = [ { class : "一年级" , student:[{ name: "王晓飞" },{ name: "陈扇" },{ name: "理查德" }], group:{ count:6 } }, { class : "二年级" , student:[{ name: "朱暖" },{ name: "张坚庭" },{ name: "刘海得" }], group:{ count:8 } }] var myTemplate = Handlebars.compile($( "#class-template" ).html()); $( "#demo2" ).html(myTemplate(data2)); }) </script> <div id= "demo3" > </div> <script id= "class2-template" type= "text/x-handlebars-template" > {{ #each this}} <dl> <dt>{{ class }}</dt> {{ #with student}} {{ #each this}} <dd>{{ this }}</dd> {{/each}} {{/ with }} </dl> {{/each}} </script> <script> $( function (){ var data2 = [ { class : "一年级" , student:[ "王晓飞" , "陈扇" , "理查德" ] }, { class : "二年级" , student:[ "朱暖" , "张坚庭" , "刘海得" ] }] var myTemplate = Handlebars.compile($( "#class2-template" ).html()); $( "#demo3" ).html(myTemplate(data2)); }) </script> <body> </body> </html> |
点击下载:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能