【发布时间】:2012-05-03 07:46:43
【问题描述】:
我有一个 Backbone 集合。我正在使用 fetch 在初始化时将 Facebook 帖子延迟加载到模型中。
https://gist.github.com/2271437
exports.Collection = class Posts extends Backbone.Collection
initialize: (models, options) =>
@id = options.id
@activeDetails = false
@on "loadDetails", @loadDetails
@on "detailsLoaded", @logger
debug "initialized posts"
@fetch
beforeSend: () =>
console.log "about to fetch..."
@trigger "postsLoading"
success: (collection, response) =>
debug "successfully loaded ajax"
@trigger "postsLoaded"
error: (collection, response) => @trigger "postsLoadingError"
由于某种奇怪的原因,当我尝试使用 beforeSend 处理程序触发事件时,事件不会触发。我可以调用任何函数,但如果任何函数尝试使用@trigger "eventName",则事件永远不会以我能够观察到的方式触发。在上面的示例中,console.log 函数工作正常,但触发失败。
有什么想法吗?成功和错误处理程序的工作非常出色。
【问题讨论】:
标签: events backbone.js coffeescript backbone-events