{"group_id_1":[{"groupd_id":"1","authority":{"19":"u6d4fu89c8u6587u7ae0","22":"u5220u9664u6587u7ae0","5":"u6743u9650u7f16u8f91","12":"u6dfbu52a0u6743u9650u7ec4","14":"u5220u9664u6743u9650u7ec4"}}],"group_id_2":[{"groupd_id":"2","authority":{"19":"u6d4fu89c8u6587u7ae0","20":"u6dfbu52a0u6587u7ae0","22":"u5220u9664u6587u7ae0","3":"u6743u9650u6d4fu89c8","4":"u6dfbu52a0u6743u9650","5":"u6743u9650u7f16u8f91","6":"u6743u9650u5220u9664","11":"u6d4fu89c8u6743u9650u7ec4","12":"u6dfbu52a0u6743u9650u7ec4","13":"u7f16u8f91u6743u9650u7ec4","14":"u5220u9664u6743u9650u7ec4","37":"u7528u6237u65e5u5fd7u67e5u770b","38":"u63a8u9001u65e5u5fd7u67e5u770b","39":"u91c7u96c6u65e5u5fd7u67e5u770b","40":"u7528u6237u767bu5f55u65e5u5fd7","41":"u4e2au4ebau4fe1u606fu4feeu6539","31":"u91c7u96c6u8ba1u5212u6d4fu89c8","32":"u6dfbu52a0u91c7u96c6u8ba1u5212","33":"u7f16u8f91u91c7u96c6u8ba1u5212","34":"u5220u9664u91c7u96c6u8ba1u5212","35":"u63a8u9001u65e5u62a5u8868u67e5u770b","36":"u91c7u96c6u65e5u62a5u8868u67e5u770b"}}],"group_id_4":[{"groupd_id":"4","authority":{"3":"u6743u9650u6d4fu89c8","4":"u6dfbu52a0u6743u9650","6":"u6743u9650u5220u9664","11":"u6d4fu89c8u6743u9650u7ec4"}}],"group_id_5":[{"groupd_id":"5","authority":{"20":"u6dfbu52a0u6587u7ae0","3":"u6743u9650u6d4fu89c8","6":"u6743u9650u5220u9664","13":"u7f16u8f91u6743u9650u7ec4","37":"u7528u6237u65e5u5fd7u67e5u770b"}}],"group_id_6":[{"groupd_id":"6","authority":{"19":"u6d4fu89c8u6587u7ae0","20":"u6dfbu52a0u6587u7ae0","21":"u7f16u8f91u6587u7ae0","22":"u5220u9664u6587u7ae0","3":"u6743u9650u6d4fu89c8","4":"u6dfbu52a0u6743u9650","5":"u6743u9650u7f16u8f91","6":"u6743u9650u5220u9664","11":"u6d4fu89c8u6743u9650u7ec4","12":"u6dfbu52a0u6743u9650u7ec4","13":"u7f16u8f91u6743u9650u7ec4","14":"u5220u9664u6743u9650u7ec4","37":"u7528u6237u65e5u5fd7u67e5u770b","38":"u63a8u9001u65e5u5fd7u67e5u770b","39":"u91c7u96c6u65e5u5fd7u67e5u770b","40":"u7528u6237u767bu5f55u65e5u5fd7","41":"u4e2au4ebau4fe1u606fu4feeu6539","31":"u91c7u96c6u8ba1u5212u6d4fu89c8","32":"u6dfbu52a0u91c7u96c6u8ba1u5212","33":"u7f16u8f91u91c7u96c6u8ba1u5212","34":"u5220u9664u91c7u96c6u8ba1u5212","35":"u63a8u9001u65e5u62a5u8868u67e5u770b","36":"u91c7u96c6u65e5u62a5u8868u67e5u770b"}}]}
一切都来源于上面这一组JSON数据,用JSON解析器可以看到这个JSON的结构,如下:
{ "group_id_1": [ { "groupd_id": "1", "authority": { "5": "权限编辑", "12": "添加权限组", "14": "删除权限组", "19": "浏览文章", "22": "删除文章" } } ], "group_id_2": [ { "groupd_id": "2", "authority": { "3": "权限浏览", "4": "添加权限", "5": "权限编辑", "6": "权限删除", "11": "浏览权限组", "12": "添加权限组", "13": "编辑权限组", "14": "删除权限组", "19": "浏览文章", "20": "添加文章", "22": "删除文章", "31": "采集计划浏览", "32": "添加采集计划", "33": "编辑采集计划", "34": "删除采集计划", "35": "推送日报表查看", "36": "采集日报表查看", "37": "用户日志查看", "38": "推送日志查看", "39": "采集日志查看", "40": "用户登录日志", "41": "个人信息修改" } } ], "group_id_4": [ { "groupd_id": "4", "authority": { "3": "权限浏览", "4": "添加权限", "6": "权限删除", "11": "浏览权限组" } } ], "group_id_5": [ { "groupd_id": "5", "authority": { "3": "权限浏览", "6": "权限删除", "13": "编辑权限组", "20": "添加文章", "37": "用户日志查看" } } ], "group_id_6": [ { "groupd_id": "6", "authority": { "3": "权限浏览", "4": "添加权限", "5": "权限编辑", "6": "权限删除", "11": "浏览权限组", "12": "添加权限组", "13": "编辑权限组", "14": "删除权限组", "19": "浏览文章", "20": "添加文章", "21": "编辑文章", "22": "删除文章", "31": "采集计划浏览", "32": "添加采集计划", "33": "编辑采集计划", "34": "删除采集计划", "35": "推送日报表查看", "36": "采集日报表查看", "37": "用户日志查看", "38": "推送日志查看", "39": "采集日志查看", "40": "用户登录日志", "41": "个人信息修改" } } ] }
(后台为了便于识别,写成了这样子,最初版本是精简版本的。)
于是用了$.each()来遍历之,写了好几层...
var obj = group_authority_list; $.each(obj, function(k, v){ if(k == "group_id_"+urlId){ $.each(v, function(kk, vv){ $.each(vv, function(kkk, vvv){ for(var i in vvv){ if(vvv[i] == urlId)continue; _inputAuthList.each(function() { if( $(this).val() == i ){ $(this).parent('span').addClass('checked'); } }); } }); }); } });
目标是把遍历到的对应权限,在输入框中选中,于是各位可以感受一下...
// 求轻拍砖