Well, I don't know what going on. I'm setting two different attributes in a Custom Lightning Component on init, one is to iteration on UI side and another one is for just reference and it holds the original value.

component.set("v.products", productRatesByInt);
component.set("v.productsTemp", productRatesByInt);

Now, if there is any change from the end user on UI, I have a method to handle it and do some changes to its dependent records and that is happening in productsTemp attribute and then setting its updated value, like below:

component.set('v.productsTemp', productsTemp);// After some change from UI

That works perfectly. But in the same method when I do below

var actualProducts = component.get("v.products");

to get actual/Original Products, which should be without any change, because it is a totally different attribute, but it is not the same. Its records are updated with the temp record's updated value, even though these are two different attributes.

Not sure why this is happening. There is no update/modifications in v.products during this whole Process. The goal I need to achieve is I want to compare what has been changed from actual record.


Hmmm, maybe for some reason the Lightning frameworks binds those together.

Can you try to make a clone of productRatesByInt by doing this: component.set("v.productsTemp", JSON.parse(JSON.stringify(productRatesByInt)));

  • Wow!!! That was one shot solution. It is isolated now. Thanks
    – Vickal
    Aug 30 '18 at 7:52
  • 2
    I'd avoid stringify/parse like that because of performance reasons, though.
    – sfdcfox
    Aug 30 '18 at 7:53
  • @sfdcfox Yes, Definitely I see the difference now. What would you think of other solution, if we avoid Stringify/parse?
    – Vickal
    Aug 30 '18 at 7:55
  • 2
    @SFDCMafia-VIC component.set("v.productsTemp", Object.assign({}, productRatesByInt)); Object.assign copies values of an object on to a different object.
    – sfdcfox
    Aug 30 '18 at 7:57
  • That is indeed a better solution. Anyways, happy that it helped!
    – Bram
    Aug 30 '18 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.