例如,我将用于测试,
在这个例子中,当我输入 filter : chart.id = 1 ,他返回给我 id 1 它返回给我 id 10 ,我将怎么做只返回 id = 1 ?
html
<div ng-app>
<div ng-controller="TodoCtrl">
<select ng-model="toAddChart" ng-options="chart.id as chart.name for chart in chartList | filter:chart.id='1'">
<option value=""></option>
</select>
</div>
</div>
范围
function TodoCtrl($scope) {
$scope.chartList = [ { "id" : 1, "name" : "chart 1", "order" : 1, "active" : false },
{ "id" : 2, "name" : "chart 2", "order" : 2, "active" : false },
{ "id" : 3, "name" : "chart 3", "order" : 3, "active" : true },
{ "id" : 4, "name" : "chart 4", "order" : 4, "active" : true },
{ "id" : 10, "name" : "chart 10", "order" : 5, "active" : true } ];
}
更新答案正确
这是 Angular 版本中的问题,对于最古老的我需要使用函数
$scope.meufiltro= function(valor){
return function(obj){
return obj.id == valor;
}
};
之后
ng-options="chart.id as chart.name for chart in chartList | filter:meuFiltro(1)"