在Ember.CollectionView渲染结束时运行jquery [英] Run jquery at the end of Ember.CollectionView rendering
问题描述
我有一个包含 CollectionView 的 ContainerView 。在屏幕上呈现 CollectionView 之后,我需要执行一个jquery函数,该功能基本上是通过渲染模板的内容来进行一些显示修改。
I have a ContainerView which contains a CollectionView. After this CollectionView renders on the screen I need to perform a jquery function which essentially looks through the content of the rendered template and performs some display modifications.
如果我在 CollectionView 的 didInsertElement 中执行该jquery,它可以在 CollectionView 中执行, / strong>在那里,我真的只需要完成一次完成。如何指定?
If I perform that jquery within the didInsertElement of CollectionView it works but it gets executed for every single element in the CollectionView where as I really just need it to be done once at the end. How do I specify that?
http://jsfiddle.net / JFqNr / (注意不会在jsfiddle或某些原因上呈现,而只是为了显示结构)
http://jsfiddle.net/JFqNr/ (note doesn't render on jsfiddle or some reason but just to show you structure)
App = Ember.Application.create();
App.FooContainerView = Ember.ContainerView.extend({
childViews: ['elementList'],
elementList: Ember.CollectionView.extend({
content: function() {
return [
{ Title: "Dashboard", ID: "dashboard" },
{ Title: "Invoices", ID: "invoices" },
{ Title: "Expenses", ID: "expenses" },
{ Title: "People", ID: "people" },
{ Title: "Reports", ID: "reports" },
{ Title: "Settings", ID: "settings" }
];
}.property(),
template: Ember.Handlebars.compile( '{{view.content.title}}' ),
didInsertElement: function() {
// perform jquery function
}
}),
didInsertElement: function() {
// does not work if perforemed here
}
});
App.initialize();
推荐答案
只有最近才被添加到主分支,所以你需要编译你自己的Ember版本。
你现在可以安排一个 afterRender
在所有个人视图被渲染后排队运行。
The functionality to do this has only very recently been added to the master branch, so you will need to be compile your own version of Ember.
You can now schedule into an afterRender
queue to run after all the individual views have been rendered.
App.FooContainerView = Ember.ContainerView.extend({
// Existing code
didInsertElement: function() {
Ember.run.scheduleOnce('afterRender', this, function(){
// perform jQuery function here;
});
}
请参阅 https://github.com/emberjs/ember.js/pull/1528 获取代码详情。
这篇关于在Ember.CollectionView渲染结束时运行jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!