猿问

就是一个 Ztree 树用到的 json! 数据很多,没全部弄出来 格式大概就是这个样,请教怎么取?

{"name": "DR", "value": "","id":"2","open": false,"icon": null,"children": [ {"name":"1","value":"", "id": "3", "open": false, "icon": null, "children": [ { "name": "1.1", "value": "","id":"4","open": false,"icon": null,"children": [ {"name":"1.1.1","value":"", "id": "5", "open": false, "icon": null, "children": [ { "name": "检查所见", "value": "1.1.1.1 内容", "id": "6", "open": false, "icon": null, "children": null, "target": "","pId": null,"url": null,"title": null}, {"name":" 诊断意见 ","value":"1.1.1.2 内容 ","id":"7","open": false,"icon": null,"children": null,"target":"", "pId": null, "url": null, "title": null } ], "target": "","pId": null,"url": null,"title": null } ],"target":"", "pId": null, "url": null, "title": null } ], "target": "","pId": null,"url": null,"title": null }, {"name":"2","value":"", "id": "8", "open": false, "icon": null, "children": [ { "name": "2.1", "value": "","id":"9","open": false,"icon": null,"children": [ {"name":"2.1.1","value":"", "id": "10", "open": false, "icon": null, "children": [ { "name": "检查所见", "value": "2.1.1.1 内容", "id": "11", "open": false, "icon": null, "children": null, "target": "","pId": null,"url": null,"title": null }, {"name":" 诊断意见 ","value":"2.1.1.2 内容 ","id":"12","open": false,"icon": null,"children": null,"target":"", "pId": null, "url": null, "title": null } ], "target": "","pId": null,"url": null,"title": null } ],"target":"", "pId": null, "url": null, "title": null } ], "target": "","pId": null,"url": null,"title": null } ],"target":"", "pId": null, "url": null, "title": null }  比如这段 json 我要根据 id 取到 value, 把 value 值传给前台弹出显示, 比如这段 json 里给后台传的 id 为 11,value 就是 2.1.1.1 内容 就这样

一只斗牛犬
浏览 114回答 2
2回答

神不在的星期二

你这个问题的关键不是如何解析JSON,而是取值方式不对。 你传给后台的id是11,那就在后台只取出该条记录就可以了,为什么还要把整个树形结构的数据都返回来呢。

慕工程0101907

第一,既然你已经把包含所有层级的json数据都拿出来,何必还要去调用服务器,直接利用js就可以展开显示了。第二,如果你想要点开一层再去服务器取出来显示,那就不需要一次拿出所有的层级数据,点某层级的展开再去取这一层的子集
随时随地看视频慕课网APP
我要回答