检索异步数据时正确的 Backbone.js 收集事件
我想在从远程服务器异步加载集合时呈现视图。我有以下集合类
class BusinessUnits extends Backbone.Collection
model: BusinessUnit
parse: (units) ->
units
然后我的观点是这样做的:
load: (businessUnits) =>
@collection = businessUnits
@collection.fetch()
@render()
显然 render() 将在获取完成之前被调用。
是否有一个在获取集合时触发的backbone.js 事件,或者我最好触发自己的事件?
这似乎是一个非常常见的场景。人们如何处理这种情况?
I want to render a view when a collection has been loaded asynchronously from the remote server. I have the following collection class
class BusinessUnits extends Backbone.Collection
model: BusinessUnit
parse: (units) ->
units
And then my view I was doing this:
load: (businessUnits) =>
@collection = businessUnits
@collection.fetch()
@render()
Obviously render() will be invoked before the fetch has been completed.
Is there a backbone.js event that is fired whenever the collection is fetched or would I be better firing my own?
This seems like a very common scenario. How do people handle this type of situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 "reset" 事件 就是您正在寻找的。
这将在获取完成后触发。
I think the "reset" event is what you are looking for.
This will be triggered after the fetch completes.