如果我的问题没有意义,我很抱歉,我会尽力解释得更好......我有一个 on 对象,在这个对象中我有一个对象数组。我正在尝试更新对象数组中找到的对象之一,我更新找到的对象,但它不会更新数组中的原始对象,现在我有这个
let vendeeCatalogs = workingVendorImplementorInfo.SVendorCatalogImplementorInfo; // This the array of objects
if (vendeeCatalogs.length > 0) {
for (let i = 0; i < vendeeCatalogs.length; i++) {
foundCatalog = workingVendorImplementorInfo.SVendorCatalogImplementorInfo.find(function (x) { return x.CatalogID == vendeeCatalogs[i].CatalogID });
if (foundCatalog) {
foundCatalog.CatalogGenerationGUID = vendeeCatalogs[i].CatalogGenerationGUID;
foundCatalog.BeginEffectiveDate = vendeeCatalogs[i].BeginEffectiveDate;
foundCatalog.EndEffectiveDate = vendeeCatalogs[i].EndEffectiveDate;
foundCatalog.Multiplier = vendeeCatalogs[i].Multiplier;
foundCatalog.Discount = vendeeCatalogs[i].Discount;
foundCatalog.UOMPrecisionTypeID = vendeeCatalogs[i].UOMPrecisionTypeID;
foundCatalog.IsSelected = vendeeCatalogs[i].IsSelected;
}
}
}
我可以看到这是错误的,因为它所做的只是更新foundCatalog,而不是找到的原始对象。 那么如何找到该对象并更新该对象以便将更改保存在workingVendorImplementorInfo.SVendorCatalogImplementorInfo 中?
最佳答案
为什么不使用 findIndex() 代替 find ?
如果您有索引,则可以执行类似的操作
vendeeCatalogs[x].CatalogGenerationGUID = ...
关于javascript - 如何从对象中的对象数组更新对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59687749/