Angularjs 如何在角度选择中使用或设置ng选项过滤器的条件
这是我的js数据Angularjs 如何在角度选择中使用或设置ng选项过滤器的条件,angularjs,Angularjs,这是我的js数据 $scope.dynamicCmb = [{ id: 1, label: 'aLabel', subItem: ['aSubItem1','aSubItem2','aSubItem3'] } , { id: 2, label: 'bLabel', subItem: [ 'bSubItem' ]
$scope.dynamicCmb = [{
id: 1,
label: 'aLabel',
subItem: ['aSubItem1','aSubItem2','aSubItem3']
}
, {
id: 2,
label: 'bLabel',
subItem: [ 'bSubItem' ]
}
];
$scope.selectedid = 2;
下面是html
<select ng-options="item.subItem for item in dynamicCmb | filter:{id:selectedid}" ng-model="selected"></select>
以上代码运行良好。如果我更新selectedid值,它将根据id字段进行过滤。但我想使用或条件,也就是说,我想基于id或标签进行搜索。所以,若我将id传递给selectedid,那个么它应该根据id进行过滤,若我为selectedid提供标签,那个么它应该根据标签进行过滤。我想做下面的事情
<select ng-options="item.subItem for item in dynamicCmb | filter:{id:selectedid | name:selectedid}" ng-model="selected"></select>
您应该按照下面的方法来实现这一点,使用这种方法在js代码中创建自定义函数
您应该按照下面的方法在js代码中使用这种方法创建自定义函数