backbone:this.$el.children().detach();的作用是什么?

backbone: What is the purpose of this.$el.children().detach();?

我正在阅读一些 backbone 源代码,在所有父视图中我看到以下代码行:

this.$el.children().detach();

虽然我不明白这样做的目的。我认为这与重置父内容有关,以防我们出于某种原因想要重新渲染父内容。是这个原因还是其他原因?

来自 jquery 文档:

The .detach() method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

http://api.jquery.com/detach/

作为示例给出的示例代码:

<p>Hello</p>
how are
<p>you?</p>
<button>Attach/detach paragraphs</button>

<script>
$( "p" ).click(function() {
  $( this ).toggleClass( "off" );
});
var p;
$( "button" ).click(function() {
  if ( p ) {
    p.appendTo( "body" );
    p = null;
  } else {
    p = $( "p" ).detach();
  }
});
</script>