开发者

jQuery : loop through nested objects

I would like to loop trough nested objects. here is my code :

var defaults = {
    toolTips: {
  开发者_如何学编程      printVersion: {
            toolTip1: {
                link_s: '#mm_tooltip1_link',
                tooltip_s: '#mm_tooltip1'
            },
            toolTip2: {
                link_s: '#mm_tooltip2_link',
                tooltip_s: '#mm_tooltip2'
            },
            toolTip3: {
                link_s: '#mm_tooltip3_link',
                tooltip_s: '#mm_tooltip3'
            }
        }
    }
};

var settings;
var $archives_dialog;

$.madmagz = function(options) {
    settings = $.extend({}, defaults, options);
    init();
};

function init(){
    initToolTips();
}

function initToolTips() {
    $(settings.toolTips).each ( function (i, tooltip_group) {
        $(tooltip_group).each (function (i, tooltip) {
            // do stuff
        });
    });
}

In every each loop, I get the same object. How can I go down in every nested objects ?


You need the $.each() helper method to loop over objects.

function initToolTips() {
    $.each(defaults.toolTips, function(i, tooltip_group) {
        $.each(tooltip_group, function(i2, tooltip) {
            alert(i2);
        });
    });
}

Ref.: jQuery.each()


Use .children()

http://api.jquery.com/children/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜