我有一个与会者阵列,其中2个也是导师。我想通过替换他/她来更新其中一名教员,并将剩余的参加者保留在阵列中。替换已更改的元素
下面是一个例子:
{
attendees: [
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' }
]
}
现在我提交教官的新数组与他们的一个改变:
{
instructors: [
{ email : '[email protected]' },
{ email : '[email protected]' }
]
}
而我最终的结果应该是:
{
attendees: [
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' }
]
}
其中[email protected]
已取代[email protected]
作为新教师。我想我可以使用_.differenceBy与lodash,但不知道如何替换数组中的已更改的元素。有没有一个优雅的方式来做到这一点?
'阵列#CONCAT(阵列)' – Rayon
这并未似乎没有道理。在原始设置中,知道某事的唯一方法是指导员通过检查电子邮件。替换之后,无法知道“测试”是一位教练。那是你要的吗? – Sigfried
没有意义 –