我只是很好奇为什么在我的example bindAttr
中不能使用数组。它会在将来实施还是故意制造,或者我缺少什么?
车把
<script type="text/x-handlebars">
<h1>Using bindAttr with objects</h1>
{{#each App.residents}}
<div {{bindAttr class="isIrish:irish"}}>{{name}}</div>
{{/each}}
</script>
<script type="text/x-handlebars">
<h1>Using bindAttr with arrays</h1>
{{#each App.residents2}}
<div {{bindAttr class="[1]:irish"}}>{{[0]}}</div>
{{/each}}
</script>
javascript
App = Ember.Application.create({
residents: [
{name: "St. Patrick", isIrish: true},
{name: "Leprechaun", isIrish: true},
{name: "Saulius", isIrish: false},
],
residents2: [
["St. Patrick",true],
["Leprechaun",true],
["Saulius",false],
]
});
最佳答案
我找到了一种使这项工作有效的方法:
<script type="text/x-handlebars">
<h1>Using bindAttr with arrays</h1>
{{#each resident in App.residents2}}
<div {{bindAttr class="resident.lastObject:irish"}}>{{resident.firstObject}}</div>
{{/each}}
</script>