2015-02-09 109 views
45

的訪問索引我有一個簡單repeat.for:奧裏利亞repeat.for項目

<li repeat.for="item of items">${item}</li> 

目前我使用:${$parent.items.indexOf(item)}。 有沒有簡寫,就像{{$ index}}的角度?

回答

85

有。寫這個:

<li repeat.for="item of items">${$index} - ${item}</li> 
+0

如果這是有益的,請upvote和接受:) – 2015-02-10 14:37:04

+0

這是直接angularjs to aurelia過渡。我不記得我第一次嘗試時做錯了什麼。 – bekite 2015-02-11 18:58:11

+5

只需注意這個索引是從零開始的。要讓您的列表從1開始,請使用以下內容: $ {$ index + 1} – 2015-03-23 15:23:25