Home > Web Front-end > JS Tutorial > js defines object array (combination) multi-dimensional array method

js defines object array (combination) multi-dimensional array method

高洛峰
Release: 2017-01-14 13:16:01
Original
1793 people have browsed it

Defining an array in php is very simple, but in js it will make an error if characters are subscripted, so combine it with objects

var top_ = {
 
    'index':'首页',
    'user':'用户',
    'tree':'模块树'
} ;
var all_list = [
    {
         
         "index": [
             {'name':'网站栏目管理','url':'1.html'},
             {'name':'网站栏目管理2','url':'2.html'}
         ]
         
          
    },
    {
        "user": [
             {'name':'用户管理','url':'user.html'},
             {'name':'用户添加','url':'add.html'}
         ]
         
    },
    {
        "tree": [
             {'name':'模块树管理','url':'manager.html'},
             {'name':'模块树添加','url':'add_new.html'},
             {'name':'模块树添333加','url':'add_ne33w.html'}
         ]
         
    }
];
Copy after login

The above defines a module tree array. . . .

In addition, when retrieving data, it is also very easy to retrieve.

//根据顶部的下标得到左边菜单
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){
//默认显示的菜单
//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_ ;
}
Copy after login

The above JS definition of object array (combination) multi-dimensional array method is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.

For more articles related to js definition of object array (combination) multi-dimensional array method, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template