我有一个ContainerView,其中包含一个CollectionView。在这个 CollectionView 在屏幕上渲染之后,我需要执行一个 jquery 函数,该函数本质上是查看渲染模板的内容并执行一些显示修改。
如果我在CollectionView的didInsertElement中执行该jquery,它会起作用,但它会针对CollectionView中的每个元素执行,因为我实际上只需要在最后完成一次。我该如何指定?
http://jsfiddle.net/JFqNr/ (注意不会在 jsfiddle 或某些原因上渲染,只是为了向您展示结构)
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();
最佳答案
执行此操作的功能最近才添加到 master 分支,因此您需要编译自己的 Ember 版本。
您现在可以安排到 afterRender
队列中,以便在渲染所有单个 View 后运行。
App.FooContainerView = Ember.ContainerView.extend({
// Existing code
didInsertElement: function() {
Ember.run.scheduleOnce('afterRender', this, function(){
// perform jQuery function here;
});
}
关于ember.js - 在 Ember.CollectionView 渲染结束时运行 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13538021/