我需要一个选项来更新另一个角度

时间:2014-02-07 16:33:32

标签: javascript angularjs filter ng-options

我设置了一个http://plnkr.co/edit/fZ6akOYipzZ7ym8dliCV?p=preview

的掠夺者

我想要第一个列表来过滤下一个列表中的组。它看起来应该很简单,但我似乎无法让它按预期运行。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

http://plnkr.co/edit/l63zgdyDeZnvNGVAar6P?p=preview

你需要在数组中使用.filter方法过滤第一个数组,并检查类型是否等于函数中的其他类型(如get(option2)

<select id="unitTypes_speciality" name="speciality" data-role="none" data-ng-model="speciality" 
ng-options="p as p.label group by p.type for p in get(options2, type)"><option>None</option></select>

$scope.get = function(myarray, type) {
  return myarray.filter(function(value) { return value.type == $scope.type.label })
}