zcgw.net
当前位置:首页 >> jquEry递归遍历json树 >>

jquEry递归遍历json树

$(function () { $("#btn_bianli").click(function () { var showlist = $(""); showall(menulist.menulist, showlist); $("#div_menu").append(showlist); }); }); //menu_list为json数据 //parent为要组合成html的容器 function showall(menu_...

var data = {"a":1,"b":2}; var u = $("").appendTo($("body")); for (var i in data) { $("").text(i + ":" + data[i]).appendTo(u); }

var obj = {};for(var k in obj) { //遍历对象,k即为key,obj[k]为当前k对应的值 console.log(obj[k]);}

方法挺多的把,可以用for循环,也可以用each方法。 先献上ajax请求: $.ajax({ url: '/path/to/file', type: 'GET', dataType: 'json', data: {param1: 'value1'}, success: function (obj){ //遍历obj } })返回的内容在success的函数里面,所有...

alert($(this).nidString);或者alert(list[i].nidString);有试过吗?

function visitData(d){ if(!d) return; $.each(d,function(k,v){ if($.isArray(this)){ visitData(this);//当前节点是数组,继续递归 }else{ //k:key 例如 "id" //v:value 例如 "19" //你要做的操作在这里继续 } });}

var r= { "data": [ { "Count": "2", "HousesName": "归墅", "Price": "1", "AddressXy": "104.047791,30.69207" }, { "Count": "1", "HousesName": "思源", "Price": "100", "AddressXy": "104.167127,30.591898" } ]}var ss = $.parseJSON(r);...

// by sleest 2016/05/10var res='{"list":[{"id":3010,"name":"青海","cityList":[{"id":3011,"name":"西宁"},{"id":3012,"name":"城东区"},{"id":3013,"name":"城西区"}]}]}';var dataObj = JSON.parse(res);var listData = dataObj.list;var ...

设置:var obj为你要遍历的json对象 $(obj).each(function(index) { var val = obj[index]; if (typeof (val.menus) == "object") { $(val.menus).each(function(ind) { alert(“销售” + val.menus[ind].menu_name); }); } else { error(); }

$.ajax({ url: "/xxxx/xxxx", type: "post", dataType: "json", success: function (datas) { var data = datas.data; if (data.length > 0) { content += '' for (var i = 0; i < data.length; i++) { content += ''; content += ''; content +...

网站首页 | 网站地图
All rights reserved Powered by www.zcgw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com