js 定義對象數組(結合)多維陣列方法_javascript技巧

來源:互聯網
上載者:User

在php中定義數組很簡單,但是在js中如果搞成字元為下標會出錯,所以結合對象來搞

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'} ]}];

 上面定義了一個模組樹 數組。。。。

另外在取出資料的時候也很好的取出

//根據頂部的下標得到左邊菜單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_ ;}

以上這篇js 定義對象數組(結合)多維陣列方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.