日期:2014-05-16  浏览次数:20368 次

如何正常遍历下面这个json字符串,实现三层菜单
数据为
 var _menus = { 'menus': [{'menuid': '1','icon': 'icon-img','menuname': '我的快捷导航',
                                  'menus': [{'menuid': '11','menuname': '我的工作台','icon': 'icon-home','url': 'DeskTop.aspx'}
                                  ]},
                                 {'menuid': '8', 'icon': 'icon-app', 'menuname': '我的工具',
                                  'menus': [{'menuid': '80','icon': 'icon-new2','menuname': '个人考勤',
                                             'menus': [{'menuid': '801','menuname': '我的考勤','icon': 'icon-log','url': '/Manage/Attend/WorkAttendAdd.aspx?type=1'},
                                                       {'menuid': '802','menuname': '我的考勤记录','icon': 'icon-new1','url': '/Manage/Attend/WorkAttendList.aspx?type=1'}
                                                      ]
                                             }
                                            ]
                                 }
                                 ]
                      };
     
下面是遍历代码,如果下面的红字改为:child,下面的代码就能正确遍历,而改为现在的menus,就不行。不知道为什么。有没有更好的方法呢。

$.each(_menus.menus, function (i, n) {
                var menulist = '';
     &n