如何检查是否Backbone.View在DOM渲染当前? [英] How can I check if a Backbone.View is currently rendered in DOM?

查看:232
本文介绍了如何检查是否Backbone.View在DOM渲染当前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查是否Backbone.View在DOM渲染当前如果不是我没有重新呈现它。我能以某种方式检查吗?

I would like to check if a Backbone.View is currently rendered in the DOM if not I don't have to rerender it. Can I check this somehow?

问候

推荐答案

那么,在理论上可以查询DOM找出来,但会比只设置一个实例变量和查询的呈现之前慢了很多。在另一方面,渲染方法(假设一切都设置正确)只应调用时模型的变化,所以你的问题表明,根据它应该如何使用你可能不使用视图(MVC样式) 。但是,假设你需要这样做,设置 this.rendered = TRUE 和检查,在渲染方法再次呈现之前可能是最快和最简单的。

Well, in theory you could query the DOM to find out, but that will be a lot slower than just setting an instance variable and querying that before rendering. On the other hand, the render method (assuming everything is set up correctly) should only be called when the model changes, so your question indicates that you are probably not using the View according to how it is supposed to be used (MVC style). But assuming you need to do this, setting a this.rendered = true and checking that before rendering again in your render method is probably the fastest and easiest.

这篇关于如何检查是否Backbone.View在DOM渲染当前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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