0

I've the following structure.

[
    {
        "Variants": [
            {
                "SellPrice": "75.00",
                "VariantID": "10",
                "VariantName": "1 L",
                "InCart": "2",
                "MRP": "115.00",
                "VariantImagePath": "/images/ruchi/710_10.png"
            },
            {
                "SellPrice": "410.00",
                "VariantID": "113",
                "VariantName": "5 L",
                "InCart": "1",
                "MRP": "485.00",
                "VariantImagePath": "/images/ruchi/710_113.png"
            },
            {
                "SellPrice": "1080.00",
                "VariantID": "219",
                "VariantName": "15L - Jar",
                "InCart": "0",
                "MRP": "1275.00",
                "VariantImagePath": "/images/ruchi/710_219.png"
            }
        ],
        "SubCategoryID": "32",
        "ProductImagePath": "/images/ruchi/710.png",
        "SubCategoryName": "Soyabean Oil",
        "BrandName": "Ruchi",
        "ProductID": "710",
        "BrandID": "117",
        "ProductName": "Ruchi soya oil"
    },
    {
        "Variants": [
            {
                "SellPrice": "58.00",
                "VariantID": "23",
                "VariantName": "900 GM",
                "InCart": "1",
                "MRP": "60.00",
                "VariantImagePath": "/images/mtr/771_23.png"
            }
        ],
        "SubCategoryID": "110",
        "ProductImagePath": "/images/mtr/771.png",
        "SubCategoryName": "Vermicelli",
        "BrandName": "MTR",
        "ProductID": "771",
        "BrandID": "167",
        "ProductName": "Seviyan Vermicelli"
    }
]

Want to filter all the data where Variants.InCart value is > 0.

In this case output will be

ProductID   VariantID   InCart
710         113         1
710         10          2
771         23          1

and this is my loop.

<tr ng-repeat="Item in ProductService.Products | <what should be filter condition here>">
    <td>{{Item.ProductID}} {{Item.Variants.VariantID}} {{Item.Variants.InCart}}</td>
</tr>

Please help.

7
  • 1
    Do you already read the documentation of the filter directive? docs.angularjs.org/api/ng/filter/filter Also it seems strange for me to have an InCart value of type string and a comparison against number 0. That does not look good. Commented Apr 4, 2015 at 11:38
  • Yes i checked that. They have not given any condition for array in array in that. Commented Apr 4, 2015 at 11:41
  • What I suggest you, create a fiddle, so that one can play with it to solve your issue. Commented Apr 4, 2015 at 11:47
  • @DeveshAgrawal if you are struggling with angular filter, than is it possible for you to filter your data inside controller itself. I think this is also the way. Commented Apr 4, 2015 at 12:08
  • @Ved Can you please share a link if you have any. Commented Apr 4, 2015 at 12:15

1 Answer 1

1
<tr ng-repeat="Item in ProductService.Products | filter:customArrayFilter">
    <td>{{Item.ProductID}} {{Item.Variants.VariantID}} {{Item.Variants.InCart}}</td>
</tr>
$scope.customArrayFilter = function (item) {
      return (item.InCart > 0);
    };

You can add custom filter like this..

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

3 Comments

But how loop will go to next variant of the same item?
is that array in array?
please create plunkr or fiddle

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.