我正在尝试在过滤器对象中传递变量以搜索相关字段,但是当我放置对象而不在其下面传递变量时,它可以正常工作:-
stock.controller.js
var vm = this;
vm.stocks = [
{
itemName:'Peanut',
labelName: 'Fortune nuts',
cost : '$4'
},
{
itemName:'Sandwich',
labelName:'Coast Food',
cost: '$10'
}
]
vm.searchOptions = {itemName:vm.search};
stock.html
<input type="text" ng-model="vm.search"/>
<tr ng-repeat="s in vm.stocks | filter:{itemName:vm.search}">
<td>{{s.itemName}}</td>
<td>{{s.labelName}}</td>
<td>{{s.cost}}</td>
</tr>
但是如果我从变量中获取对象,它将无法正常工作。接下来,我传递变量 vm.searchOptions 而不是对其进行硬编码。
<tr ng-repeat="s in vm.stocks | filter:vm.searchOptions">
<td>{{s.itemName}}</td>
<td>{{s.labelName}}</td>
<td>{{s.cost}}</td>
</tr>