我是backbonejs的新手。我面临以下错误
Uncaught TypeError: undefined is not a function backbone.js:26
这是我的代码
index.php里面的脚本标签
<script>
new App.Router;
Backbone.history.start();
App.contacts = new App.Collections.Contacts;
App.contacts.fetch().then(function () {
new App.Views.App({ collection: App.contacts });
});
</script>
main.js
(function ($) {
window.App = {
Models: {},
Collections: {},
Views: {},
Router: {}
};
window.vent = _.extend({}, Backbone.Events);
})(jQuery);
router.js
App.Router = Backbone.Router.extend({
routes: {
'': 'index'
},
index: function () {
console.log('index page');
}
});
collections.js
App.Collections.Contacts = Backbone.Collection.extend({
model: App.Models.Contact,
url : '/contacts'
});
models.js
App.Models.Appoinment = Backbone.Model.extend({
//validate
});
views.js
//Global App view
App.Views.App = Backbone.View.extend({
initialize: function () {
console.log(this.collection.toJSON());
}
});
我在这里做错了什么?
答案 0 :(得分:0)
我找到了解决方案。这就是我做的
在collections.js里面我指的是App.Models.Contact
而我没有这个模型。我创建了它,现在它可以工作。