Backbone.js 使用@key-in-handlebar获取主干模型属性
我想在Handlebar模板中获取主干模型属性。 我将数据传递给handlebar模板,它只是一个主干模型。 下面是我使用的把手模板Backbone.js 使用@key-in-handlebar获取主干模型属性,backbone.js,handlebars.js,Backbone.js,Handlebars.js,我想在Handlebar模板中获取主干模型属性。 我将数据传递给handlebar模板,它只是一个主干模型。 下面是我使用的把手模板 <table class="basic"> <thead> <th>Name</th> <th>Value</th> <th>Unit</th> <th>Description</th> </thead> <form> &
<table class="basic">
<thead>
<th>Name</th>
<th>Value</th>
<th>Unit</th>
<th>Description</th>
</thead>
<form>
<tbody>
{{#each sections}}
{{#each this.entries}}
<tr><td>{{this.name}}</td><td><input type="name" name={{@key}}/> value={{data.[@key]}} /></td><td>{{this.units}}</td><td>{{this.descrip}}</td></tr>
{{/each}}
{{/each}}
<tr>
<td></td><td class="button" colspan="4"><button id="update">{{$ 'Update'}}</button></td>
</tr>
</tbody>
</form>
</table>
下面是我想通过Handlebar呈现的json
{
"sections": [{
"entries": {
"any-key1": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key2": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key3": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
},
"name": "Entry name",
"description": "Entry description."
}, {
"entries": {
"any-key1": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key2": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key3": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
},
"name": "Entry Name",
"description": "Entry Description."
}]
}
你试过这个模型了吗?可以在将模型传递到模板中时使用它,也可以在模板中使用data.toJSON.yes,但data.[@key]似乎不起作用work@AnalogWeapon请查看我的更新。此项看起来像什么?在jsfiddle.net或jsbin.com上快速演示会很有帮助。我同意mu的观点。这是什么背景?听起来那里可能有冲突。我想看更多的代码。特别是调用模板并传递模型的代码。
{
"sections": [{
"entries": {
"any-key1": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key2": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key3": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
},
"name": "Entry name",
"description": "Entry description."
}, {
"entries": {
"any-key1": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key2": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
"any-key3": {
"name": "Name",
"units": "%",
"descrip": "desc"
},
},
"name": "Entry Name",
"description": "Entry Description."
}]
}