Hi,
I resently came by the problem in Lightning Aura development. I was developing a page to show some components on the page, the requirment was that user can deselect some of the rows and then data has to be rearranged accordingly simple right!.
I also thought so the approch I took was to have two list one for the values to display and another to hold the cloned values, so if the user rests all I can replace it with clone values and done. What happen in auro if the two variable are seprate but you filled them using a single source of reference then they are pointing to the same memory and hence if one changes other implecitly chnages. To eleminate this proble I simply used "JSON.stringify".
What this will do is when you have your values from controller to JS component then convert it into a well formated structure and then using "eval" convert it back to object. This will break the pass by reference problem and two values can be independent.
I resently came by the problem in Lightning Aura development. I was developing a page to show some components on the page, the requirment was that user can deselect some of the rows and then data has to be rearranged accordingly simple right!.
I also thought so the approch I took was to have two list one for the values to display and another to hold the cloned values, so if the user rests all I can replace it with clone values and done. What happen in auro if the two variable are seprate but you filled them using a single source of reference then they are pointing to the same memory and hence if one changes other implecitly chnages. To eleminate this proble I simply used "JSON.stringify".
What this will do is when you have your values from controller to JS component then convert it into a well formated structure and then using "eval" convert it back to object. This will break the pass by reference problem and two values can be independent.
No comments:
Post a Comment