赞
踩
直接上代码:
//将对象的数字值转为字符串
function toStringValue(obj) {
if (obj instanceof Array) {
var arr = [];
for (var i = 0; i < obj.length; i++) {
arr[i] = toStringValue(obj[i]);
}
return arr;
} else if (typeof obj == 'object') {
for (var p in obj) {
obj[p] = toStringValue(obj[p]);
}
} else if (typeof obj == 'number') {
obj = obj + '';
}
return obj;
}
//调用
console.log(toStringValue([{id:123,name:'zhangsan',pId:213},{id:234,children:[{id:435,name:23554},{id:2345}]}]))
本文地址:http://blog.csdn.net/duqian42707/article/details/52861850 转载请注明出处
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。