-3

There is a json like this

{
"SkuProduct": [
    {
        "ProductId": 2547,
        "ProductName": "T-shirt",
        "SalePrice": 0.03,
        "SkuProps": [
            {
                "PropValueId": 30,
                "PropCode": "body_type_cn"
            },
            {
                "PropValueId": 16,
                "PropCode": "color_cn"
            },
            {
                "PropValueId": 20,
                "PropCode": "size_cn"
            }
        ]
    },
    {
        "ProductId": 2553,
        "ProductName": "T-shirt",
        "SalePrice": 0.05,
        "SkuProps": [
            {
                "PropValueId": 31,
                "PropCode": "body_type_cn"
            },
            {
                "PropValueId": 16,
                "PropCode": "color_cn"
            },
            {
                "PropValueId": 20,
                "PropCode": "size_cn"
            }
        ]
    },
    {
        "ProductId": 2559,
        "ProductName": "T-shirt",
        "SalePrice": 0.07,
        "SkuProps": [
            {
                "PropValueId": 30,
                "PropCode": "body_type_cn"
            },
            {
                "PropValueId": 16,
                "PropCode": "color_cn"
            },
            {
                "PropValueId": 20,
                "PropCode": "size_cn"
            }
        ]
    },
    {
        "ProductId": 2563,
        "ProductName": "T-shirt",
        "SalePrice": 0.08,
        "SkuProps": [
            {
                "PropValueId": 31,
                "PropCode": "body_type_cn"
            },
            {
                "PropValueId": 16,
                "PropCode": "color_cn"
            },
            {
                "PropValueId": 23,
                "PropCode": "size_cn"
            }
        ]
    },
    {
        "ProductId": 2565,
        "ProductName": "T-shirt",
        "SalePrice": 0.09,
        "SkuProps": [
            {
                "PropValueId": 31,
                "PropCode": "body_type_cn"
            },
            {
                "PropValueId": 16,
                "PropCode": "color_cn"
            },
            {
                "PropValueId": 20,
                "PropCode": "size_cn"
            }
        ]
    }
],
"SellProps": [
    {
        "PropCode": "color_cn",
        "PropName": "Color",
        "Props": [
            {
                "Id": 16,
                "PName": "Red"
            }
        ]
    },
    {
        "PropCode": "size_cn",
        "PropName": "Size",
        "Props": [
            {
                "Id": 20,
                "PName": "M"
            },
            {
                "Id": 23,
                "PName": "XXL"
            }
        ]
    },
    {
        "PropCode": "body_type_cn",
        "PropName": "Type",
        "Props": [
            {
                "Id": 30,
                "PName": "165/80A"
            },
            {
                "Id": 31,
                "PName": "170/84A"
            }
        ]
    }
]

}

enter image description here

You can check the picture, when I click on the XXL options, you can find it from 'SellProps',the id is 23 , and I need to use the id to filter from 'SkuProduct', I need to loop the SkuProps from SkuProduct.. to check the PropCode names 'size_cn', as you can see, there is no match to PropValueId, it's all 20 which is size 'M', so I should diable the rest of the option.. I don't know am I descript very clear..

Is there has a simple way to check everytime when I click a option, it can tell which option should be disable or not ... and finally can get its own ProductId ..? I wrote a loop in the function, there are too many loops in the function.. its so buggy..

Jason
  • 221
  • 2
  • 3
  • 7
  • Possible duplicate of [Parse JSON in JavaScript?](http://stackoverflow.com/questions/4935632/parse-json-in-javascript) – ppasler Jan 11 '17 at 10:02

1 Answers1

0

I think I have an (untested) idea.

Since you already have the XXL id (23), you can use this value to do something like this:

SkuProduct.map(function(product) {
  return {product: product, filter: value.SkuProps.filter(function(prop) {
    return prop.PropValueId = sizeId;
  })};
});

This will return an array, that has inside an object with the product, and either a SkuProp object (if the size is found in the product's props) or nothing. Play around with that and tell me if it worked, or at least set you on the right path.

Good luck !

groooves
  • 460
  • 2
  • 7