You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wanting to allow the user to backup the data to a file, and import it. The backing up is not so much an issue as I can JSON.stringify the pocket object I presume. how would I go about importing it? I'm not sure what keys to use to set on localStorage. I see the keys are: . but would I have to manually cycle through all the stores and set the keys in the localstorage? Or, is there a nicer way that you have?
The text was updated successfully, but these errors were encountered:
@ChangePlaces Just to confirm my understanding; you are trying to save the pocket to a JSON file by using JSON.stringify(...) and then at a later time, restore the data in the JSON file to the pocket? Please correct me if I did not understand your objective correctly.
Currently, there is no functionality to achieve this by default but it can easily be done. You can iterate through the JSON from the file and override whatever is in the localStorage and then call pocket.restore() which will load the data from the localStorage into the pocket. Alternatively, you can create a pocket, load the JSON from the file, iterate through the JSON keys and add the documents to the pocket e.g.
varjsonFileContent='{"test": {"name":"test","documents":[{"forename":"Foo","surname":"Bar","_id":"914b2c31-4385-4089-8871-45a779d1202e"}],"options":{"autoCommit":true,"dbname":"pocket"},"length":1}, "user": {"name":"session","documents":[],"options":{"autoCommit":true,"dbname":"pocket"},"length":0}}';varcollections=JSON.parse(jsonFileContent);varpocket=newPocket();// Or an existing pocketObject.keys(collections).forEach(function(collection){pocket.collection(collection).remove().insert(collections[collection].documents)});
To save the data from a pocket to a JSON file I would do the following:
I'm wanting to allow the user to backup the data to a file, and import it. The backing up is not so much an issue as I can JSON.stringify the pocket object I presume. how would I go about importing it? I'm not sure what keys to use to set on localStorage. I see the keys are: . but would I have to manually cycle through all the stores and set the keys in the localstorage? Or, is there a nicer way that you have?
The text was updated successfully, but these errors were encountered: