How can I check if a Backbone.View is currently re

2019-06-18 04:30发布

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?

Regards

1条回答
我只想做你的唯一
2楼-- · 2019-06-18 04:30

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.

查看更多
登录 后发表回答