如何知道一个骨干model.fetch()完成时? [英] How to know when a Backbone model.fetch() completes?

查看:195
本文介绍了如何知道一个骨干model.fetch()完成时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绑定在我的骨干机型像这样的更改事件。

I bind on the change event of my backbone models like this.

this.model.on( "change", this.render, this );

有时候,我想获取最新版本的模型,并强行渲染视图。所以,我这样做

Sometimes I want to fetch the latest version of the model and forcibly render the view. So I do this

this.model.fetch();

不幸的是model.fetch()只有当新的数据是什么pviously存储在模型$ P ​​$不同的触发更改事件。

Unfortunately model.fetch() only fires the change event if the new data is different from what was previously stored in the model.

如何能随时触发this.render回调获取完成时,它是否会触发change事件或不?

How can I always trigger a this.render callback when fetch completes, whether it triggers a change event or not?

感谢(提前)您的帮助

推荐答案

您可以使用 $。阿贾克斯成功回调,但你也可以只听为主干同步错误在模型上的事件。 同步成功调用服务器后火灾,失败的调用服务器后错误火灾。

You can use the $.ajax success callback, but you can also just listen for the Backbone sync and error events on the model. sync fires after a successful call to the server, error fires after a failed call to the server.

this.model.on('sync', this.render, this);
this.model.on('error', this.handleError, this);

这篇关于如何知道一个骨干model.fetch()完成时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆