我很享受我第一次涉足余烬的世界,但在做一些相对简单的事情时却有点磕磕绊绊。
我想要使用类tagName附加元素的把手模板:“tr”但是有时元素不会被插入但是不显示,有时它只是一个Nx列表而没有终止符。如果我要手动添加它将完美地输出第一行,然后停止..
{{#each App.variantController.content}}
<td class="cen"><input class="variant" id="variant-{{unbound pk}}" type="checkbox"></input></td>
<td class="value">{{sku}}</td>
<td class="value">{{cost}}</td>
{{#each basic_product_options}}
<td class="value">{{content}}</td>
{{/each}}
<td class="value cen">
<a data-toggle="modal" href="#editVariationModal" class="btn btn-mini btn-warning">{% trans 'Edit' %}</a>
<a href="#" class="btn btn-mini disabled pull-right"><i class="icon-resize-vertical"></i></a>
</td>
</tr>
{{/each}}
JavaScript的:
App = Em.Application.create();
App.Variant = Em.Object.extend({
pk: null,
cost: null,
sku: null
});
App.variantController = Em.ArrayController.create({
content: [],
init: function() {
variants = eval($('script#data-variant_list').html());
for (var i = 0; i < variants.length; i++) {
this.pushObject(App.Variant.create(variants[i]));
}
}
});
App.VariantView = Em.View.create({
tagName: 'tr',
classNames: ['variant'],
templateName: 'hb-variant-list'
});
App.VariantView.appendTo('#variants-list');
jsfiddle在这里:http://jsfiddle.net/GJASM/