Ismail
Ismail

Reputation: 9592

Backbone localstorage - A "url" must be specified (without view)

I know there are more similar questions like this, but I really couldn't find the answer to my problem..

Here is my jsfiddle: http://jsfiddle.net/ktyghnL1/3/

Code:

var Todo = Backbone.Model.extend({
});

var Todos = Backbone.Collection.extend({
    model: Todo,
    localStorage: new Backbone.LocalStorage('todos-backbone'),
    comparator: 'order'
});

todos = new Todos();

I am only using models and collections for my angularjs app.

When I try to create an new todo, it fails.

Upvotes: 0

Views: 72

Answers (1)

nikoshr
nikoshr

Reputation: 33344

The models your create with var todo = new Todo(); todo.save(); don't have any information related to a local storage, you only set it on the collection.

Create a model from your todos collection, the storage will be automatically provided:

var todo = todos.create();
todo.save();

See http://jsfiddle.net/nikoshr/56awrstr/1/for a demo

Or you can create a model instance, assign it a store and add it to the collection:

var store = new Backbone.LocalStorage('todos-backbone');
var todo = new Todo();
todo.localStorage = store;
todo.save();
todos.add(todo);

http://jsfiddle.net/nikoshr/56awrstr/2/

Upvotes: 2

Related Questions