已有数组:
list:[{ community: {text: '请选择',index: -1},room: {text: "请选择",index: -1,},type: {text: "请选择",index: 0,}}]
接口返回数据:
dataList:[{door_id: "6346", community_id: "16", community: "国际城北区", house: "D区26号楼4单元4602"}, {door_id: "5442", community_id: "16", community: "国际城北区", house: "D区9号楼2单元2602"}.{door_id: "5331", community_id: "11", community: "曙光苑", house: "3号楼1A单元1单元3"}]
声明空数组arr
let arr = [];
遍历list
dataList.map(item => {
this.data.list.map(e => {
e.community.text = item.community;
e.community.index = item.community_id;
e.room.text = item.house;
e.room.index = item.door_id;
arr.push({"community":{text:item.community,index:item.community_id},"room":{text:item.house,index:item.door_id}, "type": {text: "请选择",index: 0,}})
})
}
console.log(arr) // community: {text: "国际城北区", index: 12},room: {text: "D区26号楼4单元4602", index: "6346"},type: {text: "请选择", index: 0}