我不能使它工作:

我的json

[{"myicons":[{"icon":[{"rel":"1","id":"icon1","class":"bookmark desktop-icon ui-draggable","title":"bookmark1"}]},{"icon":[{"rel":"2","id":"icon2","class":"bookmark desktop-icon ui-draggable","title":"bookmark2"}]}]}]


我的jQuery每个函数找到两个图标,但我似乎无法获取值...它一直在说未定义。

var myicons = data[0].myicons;
            $.each(myicons, function() {

                var iconid = this.id;
                alert(iconid);
});

最佳答案

您的JSON充满了数组。我datamyicons甚至icon

$.each(data, function () {
    var myicons = this.myicons;
    $.each(myicons, function () {
        var iconid = this.icon[0].id;
        alert(iconid);
    });
});


DEMO

我强烈建议您简化JSON对象

关于javascript - 在嵌套的jQuery数组中寻找值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21414485/

10-09 19:33