views:

64

answers:

2

Hello, 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 ?

A: 

Use .children()

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

Nevin
+1  A: 

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()

jAndy
Ok, that's it !Thanks a lot.
Franck