js Defines Object Array of Combined with Multidimensional Array Method

  • 2021-07-06 09:39:11
  • OfStack

In php the definition of arrays is very simple, but in js if the character for the subscript will make an error, so combined with the object to do


var top_ = {

	'index':' Home page ',
	'user':' Users ',
	'tree':' Module tree '
} ;
var all_list = [
	{
		
		 "index": [
			 {'name':' Website column management ','url':'1.html'},
			 {'name':' Website column management 2','url':'2.html'}
		 ]
		
		 
	},
	{
		"user": [
			 {'name':' User management ','url':'user.html'},
			 {'name':' User added ','url':'add.html'}
		 ]
		
	},
	{
		"tree": [
			 {'name':' Module tree management ','url':'manager.html'},
			 {'name':' Module tree addition ','url':'add_new.html'},
			 {'name':' Module tree addition 333 Plus ','url':'add_ne33w.html'}
		 ]
		
	}
];

A module tree array is defined above. . . .

In addition, it is also very good to take out the data


// Get the left menu according to the subscript at the top 
function return_left_menu_by_index(index){

var left_ = '' ;
for(var i in all_list){

for(var j in all_list[i]){ 
if(j == index){
// Menu displayed by default 
//console.dir(all_list[i][j]);
for(var k in all_list[i][index]){
//console.dir(k);
var new_onclick = 'onclick=change_right_url("'+all_list[i][index][k].url+'")' ;
left_+='<div style="width:120px; height:30px;line-height:30px;border:solid 1px; margin:3px;padding:2px;cursor:pointer" '+new_onclick+'>'+all_list[i][index][k].name+'</div>';
}
}

}
}

return left_ ;
}

Related articles: