控制器:$scope.dataList=[
{"dataClass":"0","dataName":"A1"}, {"dataClass":"0","dataName":"A2"}, {"dataClass":"1","dataName":"B1"}, {"dataClass":"1","dataName":"B2"}, {"dataClass":"2","dataName":"C1"}, {"dataClass":"2","dataName":"C2"}
]HTML範本:
幫你寫了個過濾器,把指定的dataClass去掉了:
angular.module('common', []).filter('myFilter', function () { return function (collection, keyname,value) { var output = []; angular.forEach(collection, function (item) { //过滤数组中值与指定值相同的元素 if(item[keyname]!=value){ output.push(item); } }); return output; } });
<p ng-app="myApp" ng-controller="myCtrl"> <p ng-repeat="x in items | myFilter: 'dataClass': dcValue "> {{x.dataClass}}---{{x.dataName}} </p> </p>
過濾器接收3個參數,原數組,要過濾的key,以及指定的key值。
repeat="item in dataList |filter :{'dataClass':{{varity}} }"
加花括號就可以了
幫你寫了個過濾器,把指定的dataClass去掉了:
過濾器接收3個參數,原數組,要過濾的key,以及指定的key值。
加花括號就可以了