用相同的对象ID替换对象

时间:2017-10-04 02:30:01

标签: angular ionic-framework ionic2

我有两个数组。一个是旧的。一个是新的。我正在使用Angular 2+ / Ionic 2+。我能够循环遍历这两个数组并过滤旧数组以给我匹配的对象。一旦匹配,我用新的替换旧对象。然而,我想要的数组不是更新,我仍然得到旧数组和我想要的。

[
{itemID: 10, color: "blue"}
{itemID: 11, color: "red"}
{itemID: 12, color: "green"}
]

[
{itemID: 11, color: "purple", size: "small"}
{itemID: 12, color: "yellow", size: "large"}
]

我想要的是什么:

[
{itemID: 10, color: "blue"}
{itemID: 11, color: "purple", size: "small"}
{itemID: 12, color: "yellow", size: "large"}
]

Component.ts

console.log(this.oldArray, 'before')
              this.oldArray = this.oldArray.filter(resultOne => {

                 return this.newArray.map(resultTwo => {
                  if(resultOne.itemID == resultTwo.itemID){

                      return resultOne.itemID == resultTwo.itemID
                      }
                })
              })
              console.log(this.oldArray, 'after -- I'm getting the same as before')

1 个答案:

答案 0 :(得分:1)

也许只有一点$m->to("$user->email", 'Shawn')->subject('New Notification'); $user = $this->user; Mail::send('emails.notification', [ 'doer' => $this->does, 'action' => $actions[$this->action] ], function ($m) use ($user) { $m->from('noreply@bigriss.com', 'Bigriss'); $m->to($user->email, 'Shawn')->subject('New Notification'); echo "SENT"; }); 会这样做。基本上将数组转换为对象,混合它们,然后将它们转回数组:

reduce()