对象被覆盖 - Angular 4 - 简单

时间:2017-12-05 23:15:22

标签: javascript angular typescript ionic-framework ionic3

这是一天的结束,现在无法思考。我正在动态地向我创建的对象添加数组和属性。我希望代替对象的数组被覆盖,我希望创建一个新的对象实例。我将多次遍历此函数,newObj将被最新数据覆盖,而不是相互重叠。

对象

newObj: any = {
    name: 'Unassigned',
    items: [],
  }

代码的其余部分

sortItems($event: any){

    this.newObj.name = $event[0].name
    this.newObj.items.push($event[0], this.dragData)
    console.log(this.newObj, 'added items')

    //adding object to trips
    this.items.forEach((res, i) => {
      if(res.itemId == $event[0].itemId){
        return this.items.splice(i + 1, 0, this.newObj)
      }
    })


  }

0 个答案:

没有答案
相关问题