2012-07-25 131 views
0

我只是好奇爲什麼我的examplebindAttr不適用於數組。它會在未來實施還是故意實現,或者我錯過了什麼?爲什麼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],   
    ] 
}); 

回答

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> 

+0

啊哈。確實是的。很好。其他方法是使用'class =「this.lastObject:irish」'可能。但這是一個品味問題。謝謝。 – Saulius 2012-07-25 10:30:16

+0

必須等待一分鐘.. :-) – Saulius 2012-07-25 10:30:57

+0

我想花更多的時間在你的問題。我的解決方案僅適用於具有兩個元素的數組。在一般情況下,我找不到解決此問題的方法。另一方面,我想知道爲什麼你需要這個功能。如果這是一個真正的需要,你可以推動一個問題在燼寶回購,鏈接這個問題,看看會發生什麼^^ – 2012-07-25 21:11:19

相關問題