Page 1 of 1

Copy contents of one LSV into another

Posted: Wed Sep 20, 2017 9:49 pm
by M&M

hi,

I have a Local Storage variable (LSV_A) that is based on a model. I have another LSV (LSV_B) that is based on the same model. LSV A has an array of records. What would be the best way to copy the entire contents of LSV_A into LSV_B? Do I need to iterate and copy the individual records/parameters? Thanks

Image


Copy contents of one LSV into another

Posted: Wed Sep 20, 2017 11:50 pm
by Bruce Stuart

M&M,

Since Appery 'models' are simply stored in localStorage as the equivalent of JSON.stringify() - you can move one instance of an object to another simply by saying localStorage.LSV_B = localStorage.LSV_A - again provided they are the same object model.

You can test this theory by examining an object in either Chrome or Weinre - and say oMyTempObject = JSON.parse(localStorage.LSV_A)....

Then examaming oMyTempObject by just asking for oMyTempObject at the console - and expanding the '' character.

You can then move LSV_A to LSV_B and issuing the same JSON.parse(localStorage.LSV_B)

The Appery 'models' are simply 'conveniences' (absolutely great) so that you can use the mapper on Object data stored as JSON.stringified representations of the object.

You should check out, if you get time - JSON.parse and JSON.stringify - a good working knowledge of how these work - can be invaluable.....for a number of use cases....

Best,

Bruce

Image


Copy contents of one LSV into another

Posted: Thu Sep 21, 2017 4:43 am
by M&M

hi Bruce,

Fantastic, thanks for the clear explanation! :) I have used JSON.parse and stringify for a while now but strictly in the JS context and not with models and LSV - so wanted to exercise some caution and get some opinions. Thanks once again for your help. So as you mentioned I should be able to "xcopy" one LSV (based on same model) into another :)

Cheers,
MM