【发布时间】:2015-09-30 15:05:12
【问题描述】:
在使用 Handlebar 4.0.3 的应用程序中,我有这个简单的模板:
{{#each certificates}}
<tr>
<td data-title='Certification'>{{this}}</td>
</tr>
{{/each}}
我使用这样编译它:
result = template(certificates: ['test'])
我有这个结果:
<table class="table table-hover table-condensed tablesorter">
<tbody><tr>
<td data-title="Certification">[object Object]</td>
</tr></tbody>
</table>
我认为我应该使用“test”而不是“[object Object]”。
我试过这个模板:
{{#each certificates}}
<tr>
<td data-title='Certification'>{{this}}</td>
<td data-title='Certification'>{{name}}</td>
</tr>
{{/each}}
还有这个 JavaScript :
result = template({ certificates: [{name: 'Name'}]})
我有 tyhis 的结果:
<table class="table table-hover table-condensed tablesorter">
<tbody><tr>
<td data-title="Certification">[object Object]</td>
<td data-title="Certification"></td>
</tr></tbody>
</table>
如您所见,{{name}} 没有给出任何内容而不是“名称”。
我是不是做错了什么?
编辑 1
我发现了问题。
我有这个 html :
<div id='modal-site'>
<table>
<tbody>
{{#each site.certificates}}
<tr>
<td>{{this.name}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
当我这样做 $('#modal-site').html() 时,我得到了这个结果:
{{#each site.certificates}}
{{/each}}
<table>
<tbody><tr>
<td>{{this.name}}</td>
</tr></tbody>
</table>
each 在外面,所以车把不能工作。你有解决方案的想法吗?
【问题讨论】:
-
在 HTML 中尝试
{{this.name}}(用于模板的第二个实现)。 -
你的第二个实现应该像jsbin.com/sicijiwuba/edit?html,js,console一样工作
-
@RoyMiloh,我编辑了我的问题
标签: javascript ember.js handlebars.js