我是Backbone.js的新手。我刚刚用backbone.js开始了一个项目。但我正面临一些问题。我的模特是:
define([
'underscore',
'backbone'
], function(_, Backbone) {
var Event = Backbone.Model.extend({
urlRoot: '/event',
idAttribute: 'eventID',
defaults: {
eventID: null
, eventKind: null
, eventTypeID: null
, eventDate: null
}
});
return Event;
});
收集是:
define([
'jquery',
'underscore',
'backbone',
'../newModels/event'
], function($, _, Backbone, Event){
var event = new Event();
var Events = Backbone.Collection.extend({
url: '/event',
model: event,
orderBy: "eventID",
});
return Events;
});
我的观点是:
define([
'jquery',
'underscore',
'backbone',
'../newModels/event',
'../newCollections/events',
'text!templates/Template.html'
], function($, _, Backbone,Event,EventsCollection,Template){
var sView = Backbone.View.extend({
el: $("#contentView"),
render: function(){
var eventsCollection = new EventsCollection();
var data = [];
eventsCollection.fetch({
success: function(collection,response){
alert("REST Service call was success");
alert(JSON.stringify(collection.models));
})
}
});
return sView;
});
但是当在render函数中执行eventsCollection.fetch()时,我收到以下错误:
未捕获的TypeError:this.model不是构造函数 在F.d._prepareModel(backbone-min.js:24) 在F.d.add(backbone-min.js:19)
请帮助我找出问题/我在编码时的错误。每一个帮助都会很明显。