バックボーンを学ぼうとしていますが、ここで何が間違っているのかわかりません。私のApp.wishlists.create(data);
回線が戻ってきUncaught TypeError: object is not a function
ました。どんな助けでも本当に感謝します!
/* -------------------------------------------------------------------------- */
/* src/models/wishlist.js
/* -------------------------------------------------------------------------- */
(function($, App, Wishlist) {
Wishlist.Model = Backbone.Model.extend({
defaults: {
title: ''
}
});
App.wishlist = new Wishlist.Model;
}(jQuery, WL.module('app'), WL.module('wishlist')));
/* -------------------------------------------------------------------------- */
/* src/collections/wishlists.js
/* -------------------------------------------------------------------------- */
(function($, App, Wishlist) {
Wishlist.Collection = Backbone.Collection.extend({
model: App.wishlist,
localStorage: new Backbone.LocalStorage('wishlists-backbone')
});
App.wishlists = new Wishlist.Collection;
}(jQuery, WL.module('app'), WL.module('wishlist')));
/* -------------------------------------------------------------------------- */
/* src/views/wishlist/edit.js
/* -------------------------------------------------------------------------- */
(function($, App, Wishlist) {
Wishlist.Views.Edit = Backbone.View.extend({
el: '#main',
events: {
'submit form': 'save'
},
template: _.template($('#wishlist-edit-template').html()),
render: function() {
this.$el.html(this.template());
},
save: function(e) {
e.preventDefault();
var data = $(e.target).serializeObject();
App.wishlists.create(data);
//e.preventDefault();
}
});
App.wishlistEditView = new Wishlist.Views.Edit;
}(jQuery, WL.module('app'), WL.module('wishlist')));
/* -------------------------------------------------------------------------- */
/* src/app.js
/* -------------------------------------------------------------------------- */
var WL = WL || {};
WL.module = _.memoize(function(module) {
return { Views: {} };
});
(function($, App) {
var Router = Backbone.Router.extend({
routes: {
'': 'home',
'new': 'edit',
'edit/:id': 'edit'
}
});
// on DOM ready
$(function() {
App.router = new Router;
App.router.home = function(params) {
new App.Views.Main;
};
App.router.edit = function(params) {
App.wishlistEditView.render();
};
App.router.on('route', function(route, params) {
App.router[route](params);
});
Backbone.history.start({ pushState: true });
});
}(jQuery, WL.module('app')));