خرید بک لینک

Vote count: 0

In Backbone.js, I am saving an array of collections to localstorage like so:

for (var thing of app.things) {
    localStorage.setItem('thing-' + thing.cid, JSON.stringify(thing.collection.toJSON()));
}

I can confirm these are being stored in the Chrome localstorage inspector.

I am trying to restore them with this code:

var localStorageRef = localStorage.getItem('thing-' + thing.cid);
if (localStorageRef) {
    thing.collection = JSON.parse(localStorageRef);
}

This doesn't throw an error, but it does mean that the next time I try to trigger the first code (to setItem) the following error occurs:

Uncaught TypeError: stave.collection.toJSON is not a function

Something in my second chunk of code is making the first chunk not work any longer.

asked 26 secs ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 20 ارديبهشت 1396 ساعت: 23:31

صفحه بندی