如何使用角度选择框过滤某个对象属性值

时间:2015-02-23 12:40:38

标签: angularjs

我想过滤掉属性值为"None"的对象。对象CounterParty有2个属性,CounterPartyIdCounterPartyName

数据库中的第一个对象有CounterPartyName: "None",我不希望这在选择框选项中显示。

我设置了一个plunker但是选择框不起作用且控制台中没有错误:

Plunker

  <select ng-model="search.CounterParty" 
          ng-options="c.CounterPartyName as c.CounterPartyName for c in counterPsList | unique: 'CounterPartyName'">
   {{c.CounterParty}}
 </select>

的Json

$scope.counterParties = [
  {"$id":"1","CounterPartyId":1,"CounterPartyName":"None","Documents":null},
  {"$id":"2","CounterPartyId":2,"CounterPartyName":"CounterParty A","Documents":null},
  {"$id":"3","CounterPartyId":3,"CounterPartyName":"Counter Party B","Documents":null},
  {"$id":"4","CounterPartyId":4,"CounterPartyName":"Counter Party C","Documents":null},
  {"$id":"5","CounterPartyId":5,"CounterPartyName":"Counter Party D","Documents":null}
];

1 个答案:

答案 0 :(得分:1)

你不需要在这里使用angular-ui的unique过滤器 - 它的目的是别的。

如果您只是需要根据某个属性过滤掉,可以像这样指定过滤器表达式(注意!):

ng-options = '...in counterPsList | filter: { CounterPartyName: "!None" }'

plunker