0
我會例如,用於測試,採用NG-選項我怎麼篩選究竟解釋給定值
在這個例子中,當我把過濾器: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 } ];
}
更新正確回答這個問題
這是在角版本問題,最古老的,我需要使用功能
$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)"
不行,浪得虛名。 – 2015-03-31 19:04:38
@AndrewAlex將過濾器輸入錯誤更改爲過濾器{'id':1}'嘗試更新回答 – 2015-03-31 19:06:14
繼續顯示2個結果 – 2015-03-31 19:07:59