jquery读取json内指定的内容
JSON数据:[{"id":0,"text":"\u6240\u6709\u6743\u9650","children":[{"id":"1","text":"\u987...
JSON数据:
[{"id":0,"text":"\u6240\u6709\u6743\u9650","children":[{"id":"1","text":"\u9875\u97621","children":[{"id":"3","text":"\u9875\u976211"},{"id":"5","text":"\u9875\u976212"}]},{"id":"2","text":"\u9875\u97622","children":[{"id":"4","text":"\u9875\u976221"},{"id":"6","text":"\u9875\u976222"}]}]}]
读取条件,读取ID为1,3,5的数据并显示出来 展开
[{"id":0,"text":"\u6240\u6709\u6743\u9650","children":[{"id":"1","text":"\u9875\u97621","children":[{"id":"3","text":"\u9875\u976211"},{"id":"5","text":"\u9875\u976212"}]},{"id":"2","text":"\u9875\u97622","children":[{"id":"4","text":"\u9875\u976221"},{"id":"6","text":"\u9875\u976222"}]}]}]
读取条件,读取ID为1,3,5的数据并显示出来 展开
1个回答
展开全部
用jquery each遍历
$.ajax({
url: seturl,
dataType:"JSON",
type:'POST',
data:{'mesId':detId},
cache: false,
success: function(data){
$.each(data,function(k,v){
if(v.id == 1 || v.id == 3 || v.id == 5){
}
});
}
});
$.ajax({
url: seturl,
dataType:"JSON",
type:'POST',
data:{'mesId':detId},
cache: false,
success: function(data){
$.each(data,function(k,v){
if(v.id == 1 || v.id == 3 || v.id == 5){
}
});
}
});
追问
ID为1,3,5只是举例,这个ID是变化的!不是固定的,怎么处理呢,谢了
追答
那你总有一个值的吧如果是数组 你可以在里面嵌套一个$.each
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询