我有一个包含对象的数组。在这些对象中的每一个中,itemID都有另一个对象。例如将对象合并到具有匹配ID的数组 - 角度2+/Ionic 2+
[
{object1: 123, hasObjects: {innerObjectID: 1, type: red}
{object2: 124, hasObjects: {innerObjectID: 2, type: blue}
{object3: 125, hasObjects: {innerObjectID: 2, type: blue}
{object4: 127, hasObjects: {innerObjectID: 1, type: red}
]
hasObjects是我内心的对象。我从另一个端点检索到其他对象,并且我想根据那个innerObjectID将这些数据组合到这个数组中。下面是其他物体的样子 - 每一个都是它自己的API调用
{ innerObjectID: 1, data: 1231231209381029381 }
{ innerObjectID: 2, data: 13464531209381029381 }
我想这些数据组合成阵列上方。所以我会查看该数组并添加基于ID的对象。
我想要什么:
[
{object1: 123, hasObjects: {innerObjectID: 1, type: red, data: 1231231209381029381}
{object2: 124, hasObjects: {innerObjectID: 2, type: blue, data: 13464531209381029381}
{object3: 125, hasObjects: {innerObjectID: 2, type: blue, data: 13464531209381029381}
{object4: 127, hasObjects: {innerObjectID: 1, type: red, data: 1231231209381029381}
]
Component.ts
setItems(){
this.service.setItems().subscribe((res) => {
this.items = res
this.stops.map(res => {
this.getIcons(res.hasObjects)
})
})
}
getIcons(iconID){
this.service.getIcons(iconID.imageID).subscribe(icon => {
this.newIcons = icon
icon.data = 'data:image/png;base64,' + icon.data;
let newObj = Object.assign(iconID.imageID, this.newIcons.innerObjectID)
console.log(newObj, 'new object')
})
}
什么上面发生的事情是,我刚刚起步的结果,并不能添加相关物体内部的对象。
您能指定代码中相应对象名称的可能性吗? – amal