このTodo MVC の例と同様の構造で、Require.js を使用し、Backbone LocalStorage も使用して、最初の Backbone アプリを構築しています。問題はTweetsCollection.fetch()
、HomeView で実行すると、firebug からエラーが発生することです。TypeError: options is undefined
var method = options.update ? 'update' : 'reset';
ツイートコレクション:
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();
});
ホームビュー初期化:
initialize: function() {
this.listenTo(TweetsCollection, 'add', this.addOne);
this.listenTo(TweetsCollection, 'reset', this.addAll);
this.listenTo(TweetsCollection, 'all', this.render);
TweetsCollection.fetch(); // <- Error here
},
上記の例に従おうとしましたが、これで本当に迷っています。