我想过滤掉属性值为"None"
的对象。对象CounterParty
有2个属性,CounterPartyId
和CounterPartyName
。
数据库中的第一个对象有CounterPartyName: "None"
,我不希望这在选择框选项中显示。
我设置了一个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}
];
答案 0 :(得分:1)
你不需要在这里使用angular-ui的unique
过滤器 - 它的目的是别的。
如果您只是需要根据某个属性过滤掉,可以像这样指定过滤器表达式(注意!
):
ng-options = '...in counterPsList | filter: { CounterPartyName: "!None" }'