-1

Hey guys I found this one on multiple checkboxes filter: angular js multiple checkbox with custom filters

I have a similar problem but a multilevel JSON. Something like this: http://jsfiddle.net/u9a1oLp6/5/

Especialy this part is my problem:

$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];
                });
            }
        }
    };

Any ideas?

2 Answers 2

1

The issue is quite simple, you missed out the comma in your json after the BrandMerchant
I found out by looking at the browser's Console.

{
        "MerchantName": "amazon",
        "BrandMerchant":[
            {
        "BrandList": " pepe jeans, peter england, red tape"
            }
         ], // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS COMMA HERE
         "Description": "amazon Store"
}

Also, not sure if you want to change the Brandlist into an array?
"BrandList": [item1, item2, etc]

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the issue with the comma but what I mean is the part: 'return row.BrandList.split(/,\s*/).some(function(brand)' It must look something like this: 'return row.BrandMerchant.BrandList.split(/,\s*/).some(function(brand)' to get the right object.
0

You just need to correct the code which access BrandList.

Access it through the BrandMerchant array:

$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];
            });
        }
    }
};

Also when you construct the BrandList Array for the right filter:

_.each($scope.records, function(i){
   if(i.BrandMerchant[0].BrandList)   
$scope.BrandList=_.union($scope.BrandList,i.BrandMerchant[0].BrandList.split(','       ));
});

Check this fiddle.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.