主干错误:未捕获类型错误:对象函数(){parent.apply(this,arguments); } 没有方法“on”;
任何想法为什么我在调用collection.fetch
时会收到此错误?
它在代码的这一部分中抛出:
这是触发错误的代码:
$(document).ready ->
SearchResult = Backbone.Model.extend
SearchResults = Backbone.Collection.extend
url: "/backbone/search"
model: SearchResult
parse: (response)->
console.log response
new SearchResult
id: response.id
title: response.title
searchResults = new SearchResults()
searchResults.fetch()
Any ideas why am I getting this error when I invoke collection.fetch
?
It's thrown in this section of the code:
This is the code that triggers the error:
$(document).ready ->
SearchResult = Backbone.Model.extend
SearchResults = Backbone.Collection.extend
url: "/backbone/search"
model: SearchResult
parse: (response)->
console.log response
new SearchResult
id: response.id
title: response.title
searchResults = new SearchResults()
searchResults.fetch()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题出在这行代码上:
它应该是这样的:
否则 CoffeeScript 会将
extend
函数分配给 SearchResultThe problem was with this line of code:
It should have been like this:
Otherwise CoffeeScript was assigning the
extend
function to SearchResult您实际上并没有将模型附加到集合中...
从文档中,解析应该
我还没有测试过,但我相信这会起作用
You're not actually attaching the models to the collection...
from the docs, parse should
I haven't tested it, but i believe that will work