0

"id":"236"が存在する場合は、spConfig['attributs'][125]['options']含まれている配列を取得します。

jQuery でこれをどのように行いますか?

var spConfig = {
    "attributes": {
        "125": {
            "id": "125",
            "code": "pos_colours",
            "label": "Colour",
            "options": [{
                "id": "236",
                "label": "Dazzling Blue",
                "price": "0",
                "oldPrice": "0",
                "products": ["11148"]
            }, {
                "id": "305",
                "label": "Vintage Brown",
                "price": "0",
                "oldPrice": "0",
                "products": ["11786", "11787", "11788", "11789", "11790", "11791", "11792", "11793"]
            }]
        }

    }
4

3 に答える 3

1

http://api.jquery.com/jQuery.inArray/

if ($.inArray('yourmom', myArray) !== -1) ...
于 2012-08-03T03:46:15.793 に答える
1

デモ

function findMe(searchTerm, location) {
    for ( var i = 0; i < location.length; i++ ) {
        if(location[i]['id'] == searchTerm) {
            return location[i];        
        }
    }
    return null;
}

var searchTerm = '236';
var location = spConfig['attributes']['125']['options'];

var requiredObject = findMe( searchTerm, location );
​alert( requiredObject ? requiredObject['label'] : 'Not Found');​​​​​​
于 2012-08-03T03:59:29.033 に答える