angular.js采用NG-选择仅显示唯一值 [英] angular.js using ng-options to only display unique values
本文介绍了angular.js采用NG-选择仅显示唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个数组
$scope.colors = [
{name:'black', shade:'dark'},
{name:'white', shade:'light'},
{name:'red', shade:'dark'},
{name:'red', shade:'dark'},
{name:'yellow', shade:'light'}
];
时有可能使用NG选项建立与在下拉列表中只有唯一值的选择元素,所以红色只显示一次?
Is it possible to use ng-options to build a select element with only unique values in the dropdown, so red will only display once?
推荐答案
AngularUI 正好有你需要什么,在'unique 过滤器( SRC code )。
AngularUI has exactly what you need, the ´unique´ filter (src code).
例如:
ng-options="color in colors | unique:'name'"
这篇关于angular.js采用NG-选择仅显示唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文