angular js多个复选框过滤多级JSON
angular js multiple checkboxes filters on multilevel JSON
嘿,伙计们,我在多个复选框过滤器上发现了这个:angular js多个复选盒,带有自定义过滤器
我也有类似的问题,但有一个多级JSON。类似于以下内容:http://jsfiddle.net/u9a1oLp6/5/
特别是这部分是我的问题:
$scope.searchFilter = function(row){
var mercChecked = getChecked($scope.merchantCheckboxes);
var brandChecked = getChecked($scope.brandCheckboxes);
if(mercChecked.length == 0 && brandChecked.length == 0)
return true;
else{
if($scope.merchantCheckboxes[row.MerchantName])
return true;
else{
return row.BrandList.split(/,'s*/).some(function(brand){
return $scope.brandCheckboxes[brand];
});
}
}
};
有什么想法吗?
问题很简单,在BrandMerchant之后,您错过了json中的逗号
我通过查看浏览器控制台发现了这一点。
{
"MerchantName": "amazon",
"BrandMerchant":[
{
"BrandList": " pepe jeans, peter england, red tape"
}
], // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS COMMA HERE
"Description": "amazon Store"
}
此外,不确定是否要将Brandlist更改为数组"BrandList": [item1, item2, etc]
您只需要更正访问BrandList
的代码。
通过BrandMerchant
阵列访问:
$scope.searchFilter = function(row){
var mercChecked = getChecked($scope.merchantCheckboxes);
var brandChecked = getChecked($scope.brandCheckboxes);
if(mercChecked.length == 0 && brandChecked.length == 0)
return true;
else{
if($scope.merchantCheckboxes[row.MerchantName])
return true;
else{
return row.BrandMerchant[0].BrandList.split(/,'s*/).some(function(brand){
return $scope.brandCheckboxes[brand];
});
}
}
};
此外,当您为正确的过滤器构建BrandList数组时:
_.each($scope.records, function(i){
if(i.BrandMerchant[0].BrandList)
$scope.BrandList=_.union($scope.BrandList,i.BrandMerchant[0].BrandList.split(',' ));
});
检查一下这把小提琴。
相关文章:
- 有可能过滤来自嵌入式YouTube的声音吗
- 多级HTML表单
- 为什么我的d3.jsselectAll+过滤器没有过滤
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- Angular:使用选择列表选择过滤代码中的对象
- 在单击时过滤 JSON
- 如何在BookshelfJS中通过加入来过滤结果
- 使用PHP,我如何将JSON blob附加到现有的多级JSON对象
- 如何使用javascript过滤复杂的json对象
- 如何在Javascript中创建排序、拖放多级列表
- 如何应用带过滤器的ng if来过滤记录,并在同一页面中显示两个不同的视图
- 过滤AngularJs中的数据
- 通过API调用过滤数据
- jQuery-适用于移动设备的多级菜单
- 使用angularjs内置过滤器过滤代码中的特定属性
- 如何在重建URL后从URL中传递过滤值,目的是使用Angular2和Typescript实现无限滚动
- 相对于角度控制器中的另一个阵列过滤阵列项目
- 如何在D3.js中绘制地图投影上的点,并使用范围滑块过滤数据
- angular js多个复选框过滤多级JSON
- AngularJS:使用多级 JSON 进行过滤和唯一