简体   繁体   English

如何从对象中的对象数组更新对象?

[英]How to update an object from an array of objects that is in an object?

My apologies if my question doesn't make sense, and I will try to explain it better...I have an on object and in this object I have an array of objects.如果我的问题没有意义,我很抱歉,我会尝试更好地解释它......我有一个对象,在这个对象中我有一个对象数组。 I am trying to update one of the found objects in the array of objects, I update the found object but it doesn't update the original object in the array, right now I have this我正在尝试更新对象数组中找到的对象之一,我更新了找到的对象,但它没有更新数组中的原始对象,现在我有了这个

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;
        }
    }
}

I can see that this is wrong because all it does is updates the foundCatalog, and not the original object that was found.我可以看到这是错误的,因为它所做的只是更新 foundCatalog,而不是找到的原始对象。 So how do I find the object and update that object so that the changes are saved in the workingVendorImplementorInfo.SVendorCatalogImplementorInfo?那么如何找到对象并更新该对象,以便将更改保存在 workingVendorImplementorInfo.SVendorCatalogImplementorInfo 中?

Why are you not using findIndex() in place of find ?为什么不使用 findIndex() 代替 find ?

If you have the index you can then just do something like如果您有索引,则可以执行以下操作

vendeeCatalogs[x].CatalogGenerationGUID = ... vendeeCatalogs[x].CatalogGenerationGUID = ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM