1

Can anybody tell me

is it possible to get and set values in localStorage

Here is my code

 var TodoApp = {}; 

    TodoApp.model = Backbone.Model.extend({
      defaults: {
        title : '',
        done : false
      }
    });

   TodoApp.list = Backbone.Collection.extend({
      model: TodoApp.model,
      localStorage:  new Store("local")
    });

    var todoList = new TodoApp.list()

can i use todoList.localStorage.setItem() for this

John
  • 666
  • 1
  • 9
  • 22
  • Yes, in fact there are several plugins available that make it easier to do so for example https://github.com/jeromegn/Backbone.localStorage and https://github.com/nilbus/Backbone.dualStorage – Jack Jul 17 '14 at 15:01

1 Answers1

1

localStorage is a key value persistence in the browser. All values must be strings. So you would stringify your JavaScript objects:

localStorage.setItem("myKey", JSON.stringify({foo: "bar"}));

Chris Love
  • 3,740
  • 1
  • 19
  • 16
  • Thank you Chris .. But here i want to store all data in the new localStorage object "local" my question is- can i do that manually by using some set or get stuff? – John Jul 18 '14 at 03:52
  • Yes you can, it has nothing to do with backbone. Just use the native functions – Chris Love Jul 20 '14 at 15:20