例如,我将进行测试,
在这个例子中,当我放置过滤器: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)"
最佳答案
应该是
标记
<div ng-app>
<div ng-controller="TodoCtrl">
<select ng-model="toAddChart"
ng-options="chart.id as chart.name for chart in chartList | filter:{'id': 1}: true">
<option value=""></option>
</select>
</div>
</div>
Working Fiddle作者:@RaphaelMüller
关于javascript - 使用 ng-Options 如何过滤准确解释给定值的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29376182/