无论如何,我是否可以从 Aurelia 循环之外的 Repeat.for 循环中复制索引。我正在使用索引在 for 循环内创建一个类,并且需要另一个元素来具有相同的类,但另一个元素不在循环中。有没有办法做到这一点? For循环:
<div repeat.for="conversation of conversations">
<div if.bind="!conversation.participantPhotoUrl" class="user-initials color-${$index}"><span>J</span></div>
<p class="view-date"><a click.delegate="makeActive(conversation)">View</a><span class="date">${conversation.daysAgo}</span></p>
</div>
我现在需要模板中的另一个元素(不在循环中)来具有相同的类。该元素是从
生成的click.delegate="makeActive(conversation)"
在上面的 for 循环内部。有没有办法通过该类?
最佳答案
您可以将 $index
传递给该函数。
click.delegate="makeActive(conversation, $index)
然后,在函数中将其设置为主虚拟机上的属性。
makeActive(conversation, index) {
this.activeIndex = index;
}
关于html - 在模板的另一部分使用 Aurelia for 循环中的 ${$index},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45946254/