I am building my first Backbone app with similar structure to this Todo MVC example with Require.js and also using Backbone LocalStorage. Problem is when I run TweetsCollection.fetch() in HomeView, firebug gives me error: TypeError: options is undefined var method = options.update ? 'update' : 'reset';
TweetsCollection:
define([
'underscore',
'backbone',
'backboneLocalStorage',
'models/TweetModel'
], function(_, Backbone, Store, TweetModel) {
'use strict';
var TweetsCollection = Backbone.Collection.extend({
model: TweetModel,
localStorage: new Store('tweets-storage'),
initialize: function() {
console.log('Collection init...');
}
});
return new TweetsCollection();
});
HomeView init:
initialize: function() {
this.listenTo(TweetsCollection, 'add', this.addOne);
this.listenTo(TweetsCollection, 'reset', this.addAll);
this.listenTo(TweetsCollection, 'all', this.render);
TweetsCollection.fetch(); // <- Error here
},
I try to follow the example above, but I’m really lost with this.
The line of code where the error occurs is in Backbone’s
successcallback that gets executed byBackbone.sync. Here’s what that method looks like in Backbone0.9.10:Prior to version
0.9.10, Backbone callback signature was:The
Backbone.localStorageplugin, which you are evidently using, executes the callback method as follows (line 146):As you can see, it doesn’t pass the arguments in correct order, and is missing the
optionsargument altogether, which is where you are seeing the error.So it would seem that the Backbone.localStorage plugin is currently incompatible with the newest Backbone version.
Edit: I went to report this issue to the author of the localStorage plugin, but looks like there is already a GitHub issue and pull request to fix this. It’s not merged yet, so in the meantime you can use phoey’s fork or downgrade to Backbone 0.9.9