在我ng-repeat
名單,我從一個對象數組$scope.toBuy
顯示對象元素的元素:AngularJS只顯示符合特定條件
$scope.toBuy=[
cookies={
name:'cookies',quantity:0,bought:false
},
water={
name:'water',quantity:0,bought:false
},
bananas={
name:'bananas',quantity:0,bought:false
},
milk={
name:'milk',quantity:0,bought:false
},
coconut={
name:'coconut',quantity:0,bought:false
}
];
,我初始化所有元素的bought
場false
。如何在ng-repeat
列表中顯示僅顯示bought
字段中具有false
值的元素?我嘗試這樣做:
<ul>
<li ng-repeat="item in toBuy | filter:{item.bought===false }">Buy 10 {{item.quantity}} {{item.name}} <button class="btn btn-default" ng-click="btnOnClick(item.name)"> Bought</button></li>
</ul>
但加載頁面時顯示沒有的元素。如果我刪除了過濾器,則會顯示整個列表,這意味着我錯誤地應用了過濾器。
我知道這種方法。然而,是否有可能修復過濾器呢? –