Backbone view DOM element removed

后端 未结 3 521
我在风中等你
我在风中等你 2021-02-06 16:39

I keep reading about the Backbone.js zombie (or memory leak) problem. Basically you have to unbind and remove the element from the DOM when you no longer need it to make sure al

3条回答
  •  再見小時候
    2021-02-06 17:11

    In regard to losing the page1 element in your page, and therefore not being able to populate the item with HTML, I did the following.

    Instead of using:

    this.remove();
    

    ... which removes the element entirely, and then try to figure out how to add it back, I use jQuery's:

    $(this).empty;
    

    This empties all child elements, text, and data and event handlers. More info at: http://api.jquery.com/empty/

    In fact, I use all of the following, which may be overkill but we'll see:

    this.undelegateEvents();
    $(this).empty;
    this.unbind();
    

    Hope this is useful!

提交回复
热议问题