Ember.js: How do I hook Ember.CollectionView after every child view is rendered?

This question demonstrates that overriding an Ember.View instance's didInsertElement allows you to execute some code after the view's element is in the DOM.

http://jsfiddle.net/gvUux/2/

Naturally, overriding didInsertElement on the child view class you add to an Ember.CollectionView will run the hook after each child view is rendered and inserted.

http://jsfiddle.net/BFUvK/1/

Two collection-oriented hooks on Ember.CollectionView, arrayDidChange and contentDidChange , execute after the underlying content has changed, but they execute before any rendering takes place. arrayDidChange is executed for every element added to the array, and contentDidChange wraps the content binding.

I would like to be able to hook around the rendering pipeline, something like willInsertCollection and didInsertCollection , to manipulate the DOM before and after all child elements are rendered - essentially, before and after filters around contentBinding .

Any ideas? I'm stumped.


If you want to want to do something before and/or after a view has been rendered you should use willInsertElement and/or didInsertElement respectively. In this case, since you want "to manipulate the DOM before and after all child elements are rendered" you should call those on your CollectionView.

I'm not quite sure what you mean by "before and after filters around contentBinding ", so if this doesn't answer your question if you could clarify I'd be happy to help.

jsFiddle if needed


I wanted to apply a scroll animation to slide a list up after pushing new objects. The list was rendered using an ArrayController and the #each helper. Simply triggering an event on the controller which the view subscribed to after pushing objects was causing the animation to execute before the changes to the content were actually rendered. The following technique worked perfectly for me.

//excerpt from my loadMore method on the ArrayController

var self = this;
self.content.pushObjects(moreItems);
Ember.run.scheduleOnce('afterRender', this, function()
{
  self.trigger('loadMoreComplete');
});
链接地址: http://www.djcxy.com/p/10448.html

上一篇: 在Xcode4中,你可以改变用来显示不可见的字符吗?

下一篇: Ember.js:如何在每个子视图呈现后钩住Ember.CollectionView?