gpt4 book ai didi

javascript - 为什么 bindAttr 不适用于数组

转载 作者:行者123 更新时间:2023-12-02 19:29:42 24 4
gpt4 key购买 nike

我只是好奇为什么在我的 examplebindAttr 不适用于数组。它是将来会实现还是故意制作的,还是我遗漏了一些东西?

Handlebars

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

关于javascript - 为什么 bindAttr 不适用于数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11647543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com