analyse : function (that) {
var a = new Array();
var x = 0;
$(that).children("li").each(function(){
console.log('test1');
a[x]['name'] = 'f';
a[x]['link'] = 'UUUUUUUUUUU';
console.log('test2');
x++;
})
return a;
}
I'm trying to create an array to store the hierarchy from my menu for PHP later on.
The console won't show me "test2", what did I do wrong?
Transformed into this with Didier G's Help:
analyse : function (that) {
return $(that).children('li').map(function() {
var b = {
name: $(this).children('a').text(),
link: $(this).children('a').attr('href')
};
if ($(this).children('ul').size() > 0) {
b.childs = mcms.module.analyse($(this).children('ul'));
}
return b;
});
}
So if i say var y = analyse('#menu'); I get the whole bunch! ^^
new Array()but[]a[x]is not defined so you're trying to assign a property 'name' to an undefined variable.new Array()is perfectly fine per the ECMAScript Language Specification and its implementations, but[]is shorter and its reduced compatibility is hardly relevant today.