M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Copy contents of one LSV into another

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

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Copy contents of one LSV into another

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

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

Copy contents of one LSV into another

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

Return to “Issues”