Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否存在在呈现CollectionView中的所有项目后激发的Marionette.js事件?_Javascript_Marionette - Fatal编程技术网

Javascript 是否存在在呈现CollectionView中的所有项目后激发的Marionette.js事件?

Javascript 是否存在在呈现CollectionView中的所有项目后激发的Marionette.js事件?,javascript,marionette,Javascript,Marionette,在CollectionViews和CompositeViews中,当DOM最初呈现时,以及在将项添加到视图集合的任何时候,都会触发onDomRefresh事件(这有助于视图的动态/实时性)。在我的例子中,我希望运行某个jQuery函数,但由于集合的典型长度,最好在最后一次渲染时只调用此函数一次,以防止在UI中渲染所有模型后,对我只想执行一次的操作调用过多的函数 对于这个用例,是否有一个具有适当时间的木偶事件?您可以收听“collection:rendered”。下面是CollectionView

在CollectionViews和CompositeViews中,当DOM最初呈现时,以及在将项添加到视图集合的任何时候,都会触发
onDomRefresh
事件(这有助于视图的动态/实时性)。在我的例子中,我希望运行某个jQuery函数,但由于集合的典型长度,最好在最后一次渲染时只调用此函数一次,以防止在UI中渲染所有模型后,对我只想执行一次的操作调用过多的函数

对于这个用例,是否有一个具有适当时间的木偶事件?

您可以收听“collection:rendered”。下面是CollectionView在渲染子对象时触发的内容:

this.triggerMethod("collection:rendered", this);
您可以使用以下选项:

this.listenTo(myCollectionView, "collection:rendered", _awesomeCallback);
当然,您需要更改上述内容

编辑

以下是集合视图的渲染方法:

render: function(){
    this.isClosed = false;
    this.triggerBeforeRender();
    this._renderChildren();
    this.triggerRendered();
    return this;
  }

this.triggerRendered()触发this.triggerMethod(“collection:rendered”,this),因此将在触发“collection:rendered”之前呈现集合。

我整个下午都在尝试使用Erik的解决方案,但“collection:rendered”事件从未触发。在拖网捕鱼之后,我发现源头已经不存在了:(

但是,有一种相当简单的方法可以达到人们想要的行为

在CollectionView中,使用onAddChild回调执行以下操作:

onAddChild : function() {
// Check all the models in the collection have their child views rendered
  if ( this.children.length == this.collection.length ) {
    // Now you could do something like
    this.trigger("collection:rendered");
  }
}
它之所以有效,是因为收集计数会立即上升到新的长度,而子项长度会一次更新一个

很简单,这让我很开心:) 希望它也能帮助其他人。

从V2.4.1开始,现在是
render:collection
,在
CollectionView
完成对孩子的渲染后,您应该收听它

_renderChildren: function() {
  this.destroyEmptyView();
  this.destroyChildren();

  if (this.isEmpty(this.collection)) {
    this.showEmptyView();
  } else {
    this.triggerMethod('before:render:collection', this);
    this.startBuffering();
    this.showCollection();
    this.endBuffering();
    this.triggerMethod('render:collection', this);

    if (this.children.isEmpty()) {
      this.showEmptyView();
    }
  }
},

我建议不要使用mexitalian的答案来检查
children.length==collection.length
是否会在方法
onAddChild()
中触发两次

??编辑:哦,很抱歉,没有看到您请求CollectionView。没问题,
CompositeView
方法也可以工作,但不是
itemView
。这不准确。。。集合:渲染在渲染任何项之前激发。据我所知,知道何时呈现所有项的唯一方法是侦听itemview:item:rendered,保留一个计数并将其与collection.lengthAdded render()方法代码进行比较,该方法代码显示在呈现子项之前不会触发“collection:rendered”。我将假设这是最新和最伟大的,请有人告诉我,如果这是错误的,因为我现在没有使用木偶。