在标题中,我正在尝试编辑一个我拥有索引的元素,当我这样做时,所有元素都被编辑。我在list中添加了一些元素,这是我模型的属性,但是该元素被添加到所有elemenets列表中而不是仅添加到此列表中。
unitsViewModel: Array<UnitViewModel> = [];
mapUnitToViewModel(unit: Unit, serverId: number) {
var index = this.checkIfUnitExist(unit.code);
if (index) {
//here I am adding component to componenets list(property of unitViewModelwhh)
this.unitsViewModel[index].component.push({
componentId: unit.id,
serverId: serverId
});
}
else {
this.componenetArray.length = 0;
this.componenetArray.push({
componentId: unit.id,
serverId: serverId
});
this.unitsViewModel.push(
{
id: ++this.idIndex,
component: this.componenetArray,
label: unit.code
});
}
}