JS defines an array of objects (combined) Multidimensional array method _javascript techniques

Source: Internet
Author: User

The definition of the array in PHP is simple, but in JS if the character for the next RCAs error, so the combination of objects to engage in

var top_ = {

	' index ': ' Home ',
	' user ': ' Users ',
	' tree ': ' Module Trees '
};
var all_list = [
	{
		
		 "index": [
			 {' name ': ' website column management ', ' url ': ' 1.html '},
			 {' name ': ' website column Management 2 ', ' url ': ' 2.html ' }
		 ]
		
		 
	},
	{
		"user": [
			 {' name ': ' admin ', ' url ': ' user.html '},
			 {' name ': ' user added ', ' url ': ' Add.html '}
		 ]
		
	},
	{
		"tree": [
			 {' Name ': ' Module Trees management ', ' url ': ' manager.html '},
			 {' name ': ' Module tree add ', ' url ': ' add_new.html '},
			 {' name ': ' Module tree Tim 333 Plus ', ' url ': ' add_ne33w.html '}
		 ]
		
	}
;

The above defines a module tree array ....

It's also very good to take out the data.

The left menu
function Return_left_menu_by_index (index) {

var Left_ = '
is obtained according to the subscript at the top. for (var i in all_list) {

for (Var j in All_list[i]) { 
if (j = = index) {
//default menu displayed
//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_;
}

The above JS definition object Array (combined) multidimensional array method is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.