LEATH
2018-09-05 14:09:34
第一個(gè):{ p: "category", category1: "001", name1: "100", category2: "001", name2: "100", category3: "001", name3: "100", category12: "001", name12: "100",}第二個(gè)value對(duì)應(yīng)上面的nameX{ p: "category", category: [ { value: "001", name: "100" }, { value: "001", name: "100" }, { value: "001", name: "100" }, { value: "001", name: "100" } ]}如何將第一個(gè)轉(zhuǎn)換成第二個(gè)?
1 回答

Cats萌萌
TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊
var obj = {p: "category",category : []};
var src = {
p: "category",
category1: "001",
name1: "100",
category2: "001",
name2: "100",
category3: "001",
name3: "100",
category12: "001",
name12: "100",
};
for(var key in src){
if(/category/.test(key)){
obj.category.push({
value : src[key],
name : src['name' + key.match(/\d+/)[0]]
});
}
}
添加回答
舉報(bào)
0/150
提交
取消