Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a Backbone.View is currently rendered in 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?

Regards

like image 289
bodokaiser Avatar asked Sep 08 '12 16:09

bodokaiser


1 Answers

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.

like image 175
Marius Kjeldahl Avatar answered Sep 20 '22 17:09

Marius Kjeldahl