1

例如,我将用于测试,

在这个例子中,当我输入 filter : chart.id = 1 ,他返回给我 id 1 它返回给我 id 10 ,我将怎么做只返回 id = 1 ?

http://jsfiddle.net/H6AZ2/37/

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)"
4

1 回答 1

3

它应该是

标记

<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>

@RaphaelMüller 的工作小提琴

于 2015-03-31T18:51:38.337 回答