如何使用多个复选框以角度创建服务器端过滤,当我单击应用过滤器时,应根据检查的输入字段过滤数据,并应删除单击清除过滤器并显示所有数据。这是json
{
items:[
{itemName:"apple",itemCategory:"fruits",itemStatus:"available",shipping:"nonshippable"},
{itemName:"mobile",itemCategory:"electronics",itemStatus:"notavailable",shipping:"shippable"},
{itemName:"camera",itemCategory:"gadgets",itemStatus:"available",shipping:"shippable"},
{itemName:"laptop",itemCategory:"computers",itemStatus:"notavailable",shipping:"shippable"},
{itemName:"jeans",itemCategory:"clothes",itemStatus:"available",shipping:"shippable"},
{itemName:"nike",itemCategory:"shoes",itemStatus:"available",shipping:"shippable"},
],
filters:[
{label:"apple"},
{label:"laptop"},
{label:"jeans"},
{label:"nike"},
{label:"camera"}
]
}
当你看到我的过滤器json和项目都在同一个json文件中时。
答案 0 :(得分:0)
试试这个
<div ng-repeat="filter in filters">
<label>{{filter.label}}</label>
<input type="checkbox" ng-model="filterCriteria" value="{{filter}}" ng-click="someFunc(filter)">
</div>
控制器
$scope.someFunc = function(filter){
//do the logic
var arr = [];
var idx = arr.indexOf(report);
if(idx>-1){
arr.splice(idx,1);//unchecked values remove from arr
}else{
arr.push(filter);
}
console.log(arr);//if checked values added into arr
}