Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查 Backbone.View 当前是否在 DOM 中呈现,如果不是,我不必重新呈现它。我可以以某种方式检查吗?
问候
好吧,理论上你可以查询 DOM 来找出答案,但这比仅仅设置一个实例变量并在渲染之前查询它要慢得多。另一方面,渲染方法(假设一切设置正确)只应在模型更改时调用,因此您的问题表明您可能没有按照应该使用的方式使用视图(MVC 风格) . 但是假设您需要这样做,this.rendered = true在您的渲染方法中再次渲染之前设置并检查它可能是最快和最简单的。
this.rendered = true