这似乎几乎是集合的标准用法,但它不起作用。我在文档就绪函数中有以下代码:
$(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();
});
我用 Chromium 和 Firefox 测试过,FF 更冗长:
this.model is not a constructor at Backbone.js line:570
[Break On This Error] model = new this.model(attrs, {collection: this});
我错过了什么?
作为旁注,如果您需要更多上下文,我正在尝试遵循Chris Storm 的教程/链。
相关软件版本:
- jQuery JavaScript 库 v1.7.1
- 骨干网.js 0.5.3
- 下划线.js 1.2.2
- Chromium 14.0.835.202(开发者内部版本 103287 Linux)Ubuntu 11.10
- Firefox 是 8.0,Ubuntu 11.10,64 位
更新:再调试一下,我发现在抛出错误时, this.model 具有值function Event() { [native code] }
并且调用new Event()
会抛出更多错误 - TypeError
。那么创建事件有什么问题呢?