为什么bindAttr不使用数组

时间:2012-07-25 10:17:18

标签: javascript ember.js handlebars.js

我很好奇为什么我的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],        
    ]
});

1 个答案:

答案 0 :(得分:2)

我找到了一种方法来完成这项工作:

<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>