lmmp.net
当前位置:首页 >> js或者JAvA 遍历json数组 实现如下功能 跪求大神 >>

js或者JAvA 遍历json数组 实现如下功能 跪求大神

/** * json格式转树状结构 * @param{json}json数据 * @param{String}id的字符串 * @param{String}父id的字符串 * @param{String}children的字符串 * @return{Array}数组 */function transData(a, idStr, pidStr, chindrenStr){var r = [], hash ...

var origin = [{"first_id":1,"first_name":"中学","second_id":"1-1","second_name":"一年级","third_id":"1-1-1","third_name":"一年级一班","people":10,"age":10,"parent":5},{"first_id":1,"first_name":"中学","second_id":"1-1","second_...

var Sum = function(List,Field){var S = 0,T,F;for (F = 0;F < List.length;++F){T = List[F]T.children && (T[Field] += Sum(T.children,Field))S += T[Field]}return S},F;for (F = b.length;F--;){switch (b[F].type){case 'sum' : Sum(a,b[...

var c = a.concat(b),//合并成一个数组temp = {},//用于id判断重复result = [];//最后的新数组//遍历c数组,将每个item.id在temp中是否存在值做判断,如不存在则对应的item赋值给新数组,并将temp中item.id对应的key赋值,下次对相同值做判断时...

估撞车韵pjduh641

var typeArr = new Array();for(var i = 0;i

var data = [{ id: 0, chiild: [{ msg: '111' }, { msg: '222'}] }, { id: 3, chiild: [{ msg: '444' }, { msg: '555'}] }, { id: 2, chiild: [{ msg: '467' }, { msg: '58912'}]}]; var str = ""; var strmsg = ""; for (var i = 0; i < data....

比如现在有一个json对象为jsonObj,需要给这个对象添加新的属性newParam,同时给newParam赋值为pre。做法如下: var jsonObj={ 'param1':22, 'param2' :33 }; jsonObj. newParam ='pre'; 新的属性添加以后,json对象变成: var jsonObj={ 'param...

代码太长,看演示吧。 http://jsfiddle.net/2vxsbtkx/

var json={"a":"aaa","b":{"c":"ccc","d":[{"e":"01","g":"kkkk"},{"e":"07","g":"lllll"},{"e":"05","g":"xxxxx"},{"e":"03","g":"kkkk"}]}};var arr=[];for(var i=0;i

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