This seems pretty much as a standard use of a collection, but it doesnt work. I have the following code inside a document ready function:
$(function() {
window.EventList = Backbone.Collection.extend({
model: Event,
url: '/events',
parse: function(response) { // same result with or without parse function
return _(response.rows).map(function(row) { return row.doc ;});
}
});
window.Events = new EventList;
// throws Uncaught TypeError: Illegal constructor
// Events.fetch();
});
I've tested with Chromium and Firefox, FF is more verbose:
this.model is not a constructor at Backbone.js line:570
[Break On This Error] model = new this.model(attrs, {collection: this});
What am I missing?
As a sidenote, I'm trying to follow Chris Storm's tutorial/chain if you need a bit more context.
Relevant Software Versions:
Update: a little more debugging and I find that at the point the error is thrown, this.model has the value function Event() { [native code] } and calling new Event() throws more errors - TypeError. So what's wrong with creating events?
Your problem is that you (and Chris Storm) have simply chosen a bad name for your model. There is already an Event in JavaScript (at least in a JavaScript that is wired up to a DOM); furthermore, you can't call new Event() to create a DOM Event object, you're supposed to use document.createEvent('Event').
Try renaming your Event to, say, CalendarEvent:
$(function() {
window.CalendarEvent = Backbone.Model.extend({});
window.CalendarEventList = Backbone.Collection.extend({
model: CalendarEvent,
url: '/events',
parse: function(response) {
return _(response.rows).map(function(row) { return row.doc ;});
}
});
window.CalendarEvents = new CalendarEventList;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With