它抛出了这个错误:Uncaught TypeError: Cannot call method 'fetch' of undefined in view。@collection 在视图中是未定义的,尽管它似乎是通过路由器传递的。
如果你很好奇,ajaxSubmit 被用于处理文件上传。
有任何想法吗?
路由器/tracks.js.coffee
...
initialize: ->
@collection = new Jambox.Collections.Tracks()
@collection.fetch() # works!
new: (name) ->
view = new Jambox.Views.TracksNew(name, collection: @collection)
意见/曲目/new.js.coffee
events:
'click #submit': 'uploadTrack'
uploadTrack: (e) ->
e.preventDefault()
$(@el).find('#new-track').ajaxSubmit(
success: => @collection.fetch() # Uncaught TypeError
)
...