我想重置已過濾的庫存數組,因此它會在點擊<option value="">Barcodes</option>
時顯示所有庫存。到目前爲止,當我選擇一個條形碼,之後它只顯示過濾的數據。以angularjs重置已過濾的數據
$scope.filter = function(barcode) {
var filtered = [];
for(var i = 0; i < $scope.inventories.length; i++){
if($scope.inventories[i].barcode == barcode){
filtered.push($scope.inventories[i]);
}
}
$scope.inventories = filtered;
};
<select ng-model="inventory.barcode" ng-change="filter(inventory.barcode)">
<option value="">Barcodes</option>
<option ng-repeat="inventory in inventories" value="{{inventory.barcode}}">{{inventory.barcode}}</div>
</select>
應用過濾功能時,您將要覆蓋所有的庫存NG-選項使用,爲您更換帶過濾數組的$ scope.inventories數組。看看角度過濾器的功能,特別是這個例子:http://docs.angularjs.org/api/ng/filter/filter – Capricorn