当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - Create array inside array

问题描述:

I am trying to create a tree of elements like below:

Div 1-1

Div 2-1

Div 1-2

div 2-2

div 3-1

div 4-1

and so on..

What I need to do is to create array with sub arrays and push all elements of the div.

 for (var i = 1 ; i <= 4; i++){

var headers = new Array();

var siblings = new Array();

var j = 1;

$( ".header"+i ).each(function() {

$('.fr-placeholder').remove();

var txt = $(this).text();

$(this).attr('id', 'header'+i+'-'+j);

siblings.push([i,j]);

j++;

if(txt.length != 0){

var divId = $(this).attr('id');

$('#outline').append('<li><a data-id="'+divId+'" >'+txt+'</a></li>' );

}

});

headers.push(siblings);

}

But I need to do this for all sub -elements and create array inside array inside array... Any help?

分享给朋友:
您可能感兴趣的文章:
随机阅读: