Javascript angular js多级JSON上的多个复选框过滤器
嘿,伙计们,我在多个复选框过滤器上找到了这个: 我有一个类似的问题,但有一个多级JSON。 大概是这样的: 特别是这部分是我的问题:Javascript angular js多级JSON上的多个复选框过滤器,javascript,json,angularjs,checkbox,filter,Javascript,Json,Angularjs,Checkbox,Filter,嘿,伙计们,我在多个复选框过滤器上找到了这个: 我有一个类似的问题,但有一个多级JSON。 大概是这样的: 特别是这部分是我的问题: $scope.searchFilter = function(row){ var mercChecked = getChecked($scope.merchantCheckboxes); var brandChecked = getChecked($scope.brandCheckboxes); if(mercChe
$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"
}
{
“商品名称”:“亚马逊”,
“品牌商人”:[
{
“品牌列表”:“佩佩牛仔裤,彼得英格兰,繁文缛节”
}
],//您只需更正访问品牌列表的代码即可
通过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(',' ));
});
检查此项。谢谢逗号问题,但我的意思是“return row.BrandList.split(/,\s*/).some(function(brand)”。它必须看起来像这样:“return row.BrandMerchant.BrandList.split(/,\s*/)。some(function(brand)”,以获得正确的对象。非常感谢。对我来说效果很好!