Javascript 开始使用把手
我第一次在车把周围闲逛;我的目标是在html中显示项目列表 这是html中的脚本:Javascript 开始使用把手,javascript,handlebars.js,Javascript,Handlebars.js,我第一次在车把周围闲逛;我的目标是在html中显示项目列表 这是html中的脚本: <div> <script id="list-items" type="text/x-handlebars-template"> {{#each list}} {{ price }} {{/each}} </script> </div> 我的代码不起作用,我在控制台中没有看到任何错误。 我做错了什么?您的模板迭代了列表属性,但传递了原始数组 若要
<div>
<script id="list-items" type="text/x-handlebars-template">
{{#each list}} {{ price }} {{/each}}
</script>
</div>
我的代码不起作用,我在控制台中没有看到任何错误。
我做错了什么?您的模板迭代了
列表
属性,但传递了原始数组
若要协调模板和传递的数据,请传递具有列表
属性的对象:
$(document.body).append (theTemplate ({
list: list
}));
或者修改模板以迭代数组:
<script id="list-items" type="text/x-handlebars-template">
{{#each .}} {{ price }} {{/each}}
</script>
{{{}{{{price}{{{/each}}
<script id="list-items" type="text/x-handlebars-template">
{{#each .}} {{ price }} {{/each}}
</script>