2016-12-07 69 views
0

在大多数情况下,我只是用$索引操作期间和豆腐操作来实现记录的唯一

<p ng-repeat="contact in contacts track by $index ">{{ $index }}</p> 

但我怎么能访问由轨道产生我的自定义指标,如下

<p ng-repeat="contact in contacts track by contacts.name ">{{ how to use this ($index not giving this to me) }}</p> 

秀有没有办法做到这一点?我需要这样做,因为旧$索引不能处理多个过滤器。

+1

你并不需要使用'轨道由$ index'得到索引,你可以使用'$ index'不使用'轨道by'。你能解释一下在你的案例中“自定义索引”是什么? –

+0

如果你用** x.y **'_做__track,你的自定义索引不是别的,而是** x.y **,你可以在范围内的任何地方访问它。 – Tobi

回答

0

您可以使用这样

<p ng-repeat="contact in contacts track by $index " ng-init="firstIndex = $index" >{{ firstIndex }} 
    <p ng-repeat="contact in contacts track by $index " ng-init="secondIndex = $index">{{ secondIndex }}</p> 
</p> 
+0

我想用我的自定义ID替换角度js默认索引 –

+0

@ShailendraSharma自定义ID意味着你想用特定的id开始ng-repeat? –