AngularJS基于索引的滤波器阵列

AngularJS Filter Array Based On Index

本文关键字:滤波器 阵列 索引 于索引 AngularJS      更新时间:2023-09-26

我有一个数组,比如

$scope.myList = 
[
 ["one","two","three"],
 ["a","b","c"],
 ["one","two","three"]
]

现在我想用ng repeat列出带过滤器的第三个索引。

<select >
    <option ng-repeat="item in myList| filter:item[2]:'text_here'">
         {{item[2]}} 
    </option>
</select><br/>

如何过滤每个数组的第3nd个元素并应用适当的过滤器?我确信我上面的回答是错误的。

假设您希望输出为three,c,three,则不需要过滤器。你只需要通过http://docs.angularjs.org/api/ng/directive/select

<select ng-options="item[2] as item[2] for item in myList"></select>

如果你只想列出$scope.myList中第三个数组的索引,那么你应该做这个

<select ng-options="item as item for item in myList[2]"></select>