87,968
社区成员
发帖
与我相关
我的任务
分享
var data = [{
"title": "机构名称",
"tier": "2",
}, {
"title": "姓名",
"tier": "2",
}, {
"title": "身份证号",
"tier": "1",
}, {
"title": "身份证地址",
"tier": "1",
}, {
"title": "联系电话",
"tier": "1",
}, {
"title": "备注",
"tier": "1",
}]
var newdata=[];
newdata[0] = [];
newdata[1] = [];
$.each(data,function(k,v){
if(v.tier == 1){
newdata[0].push(v);
}
if(v.tier == 2){
newdata[1].push(v);
}
});
console.log(newdata);
var newdata = [];
for(var i = 0; i < data.length; i++){
var n = parseInt(data[i].tier, 10) - 1;
if (typeof newdata[n] == 'undefined'){
newdata[n] = [];
}
newdata[n].push(data[i]);
}
console.log(newdata);