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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With