博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery遍历复杂的JSON数据
阅读量:5072 次
发布时间:2019-06-12

本文共 5355 字,大约阅读时间需要 17 分钟。

{"group_id_1":[{"groupd_id":"1","authority":{"19":"\u6d4f\u89c8\u6587\u7ae0","22":"\u5220\u9664\u6587\u7ae0","5":"\u6743\u9650\u7f16\u8f91","12":"\u6dfb\u52a0\u6743\u9650\u7ec4","14":"\u5220\u9664\u6743\u9650\u7ec4"}}],"group_id_2":[{"groupd_id":"2","authority":{"19":"\u6d4f\u89c8\u6587\u7ae0","20":"\u6dfb\u52a0\u6587\u7ae0","22":"\u5220\u9664\u6587\u7ae0","3":"\u6743\u9650\u6d4f\u89c8","4":"\u6dfb\u52a0\u6743\u9650","5":"\u6743\u9650\u7f16\u8f91","6":"\u6743\u9650\u5220\u9664","11":"\u6d4f\u89c8\u6743\u9650\u7ec4","12":"\u6dfb\u52a0\u6743\u9650\u7ec4","13":"\u7f16\u8f91\u6743\u9650\u7ec4","14":"\u5220\u9664\u6743\u9650\u7ec4","37":"\u7528\u6237\u65e5\u5fd7\u67e5\u770b","38":"\u63a8\u9001\u65e5\u5fd7\u67e5\u770b","39":"\u91c7\u96c6\u65e5\u5fd7\u67e5\u770b","40":"\u7528\u6237\u767b\u5f55\u65e5\u5fd7","41":"\u4e2a\u4eba\u4fe1\u606f\u4fee\u6539","31":"\u91c7\u96c6\u8ba1\u5212\u6d4f\u89c8","32":"\u6dfb\u52a0\u91c7\u96c6\u8ba1\u5212","33":"\u7f16\u8f91\u91c7\u96c6\u8ba1\u5212","34":"\u5220\u9664\u91c7\u96c6\u8ba1\u5212","35":"\u63a8\u9001\u65e5\u62a5\u8868\u67e5\u770b","36":"\u91c7\u96c6\u65e5\u62a5\u8868\u67e5\u770b"}}],"group_id_4":[{"groupd_id":"4","authority":{"3":"\u6743\u9650\u6d4f\u89c8","4":"\u6dfb\u52a0\u6743\u9650","6":"\u6743\u9650\u5220\u9664","11":"\u6d4f\u89c8\u6743\u9650\u7ec4"}}],"group_id_5":[{"groupd_id":"5","authority":{"20":"\u6dfb\u52a0\u6587\u7ae0","3":"\u6743\u9650\u6d4f\u89c8","6":"\u6743\u9650\u5220\u9664","13":"\u7f16\u8f91\u6743\u9650\u7ec4","37":"\u7528\u6237\u65e5\u5fd7\u67e5\u770b"}}],"group_id_6":[{"groupd_id":"6","authority":{"19":"\u6d4f\u89c8\u6587\u7ae0","20":"\u6dfb\u52a0\u6587\u7ae0","21":"\u7f16\u8f91\u6587\u7ae0","22":"\u5220\u9664\u6587\u7ae0","3":"\u6743\u9650\u6d4f\u89c8","4":"\u6dfb\u52a0\u6743\u9650","5":"\u6743\u9650\u7f16\u8f91","6":"\u6743\u9650\u5220\u9664","11":"\u6d4f\u89c8\u6743\u9650\u7ec4","12":"\u6dfb\u52a0\u6743\u9650\u7ec4","13":"\u7f16\u8f91\u6743\u9650\u7ec4","14":"\u5220\u9664\u6743\u9650\u7ec4","37":"\u7528\u6237\u65e5\u5fd7\u67e5\u770b","38":"\u63a8\u9001\u65e5\u5fd7\u67e5\u770b","39":"\u91c7\u96c6\u65e5\u5fd7\u67e5\u770b","40":"\u7528\u6237\u767b\u5f55\u65e5\u5fd7","41":"\u4e2a\u4eba\u4fe1\u606f\u4fee\u6539","31":"\u91c7\u96c6\u8ba1\u5212\u6d4f\u89c8","32":"\u6dfb\u52a0\u91c7\u96c6\u8ba1\u5212","33":"\u7f16\u8f91\u91c7\u96c6\u8ba1\u5212","34":"\u5220\u9664\u91c7\u96c6\u8ba1\u5212","35":"\u63a8\u9001\u65e5\u62a5\u8868\u67e5\u770b","36":"\u91c7\u96c6\u65e5\u62a5\u8868\u67e5\u770b"}}]}

  一切都来源于上面这一组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');						}					});				}			});		});	}});

  目标是把遍历到的对应权限,在输入框中选中,于是各位可以感受一下...

    

// 求轻拍砖

转载于:https://www.cnblogs.com/leesen/p/5424580.html

你可能感兴趣的文章
从.NET中委托写法的演变谈开去(上):委托与匿名方法
查看>>
小算法
查看>>
201521123024 《java程序设计》 第12周学习总结
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
IdentityServer4-用EF配置Client(一)
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>
Windows Phone开发(4):框架和页 转:http://blog.csdn.net/tcjiaan/article/details/7263146
查看>>
Unity3D研究院之打开Activity与调用JAVA代码传递参数(十八)【转】
查看>>
python asyncio 异步实现mongodb数据转xls文件
查看>>
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
[ZJOI2007]棋盘制作 【最大同色矩形】
查看>>
IOS-图片操作集合
查看>>
模板统计LA 4670 Dominating Patterns
查看>>
团队项目开发客户端——登录子系统的设计
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
session如何保存在专门的StateServer服务器中
查看>>
react展示数据
查看>>
测试计划
查看>>