Ember.js 在Ember.CollectionView渲染结束时运行jquery
我有一个包含CollectionView的ContainerView。在这个CollectionView在屏幕上呈现之后,我需要执行jquery函数,该函数主要查看呈现模板的内容并执行一些显示修改 如果我在CollectionView的didInsertElement中执行该jquery,它会工作,但它会针对CollectionView中的每个元素执行,而我实际上只需要在最后执行一次。我如何具体说明 注释不会在JSFIDLE上呈现或出于某种原因呈现,只是为了向您展示其结构Ember.js 在Ember.CollectionView渲染结束时运行jquery,ember.js,Ember.js,我有一个包含CollectionView的ContainerView。在这个CollectionView在屏幕上呈现之后,我需要执行jquery函数,该函数主要查看呈现模板的内容并执行一些显示修改 如果我在CollectionView的didInsertElement中执行该jquery,它会工作,但它会针对CollectionView中的每个元素执行,而我实际上只需要在最后执行一次。我如何具体说明 注释不会在JSFIDLE上呈现或出于某种原因呈现,只是为了向您展示其结构 App = Ember
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队列中,以便在渲染所有单个视图后运行
App.FooContainerView = Ember.ContainerView.extend({
// Existing code
didInsertElement: function() {
Ember.run.scheduleOnce('afterRender', this, function(){
// perform jQuery function here;
});
}
有关代码详细信息,请参阅。执行此操作的功能最近才添加到主分支中,因此您需要编译自己的Ember版本。 现在,您可以将时间安排到afterRender队列中,以便在渲染所有单个视图后运行
App.FooContainerView = Ember.ContainerView.extend({
// Existing code
didInsertElement: function() {
Ember.run.scheduleOnce('afterRender', this, function(){
// perform jQuery function here;
});
}
有关代码详细信息,请参阅。这非常有用,很可能会解决我现在在使用Ember.run.next对dom元素执行代码时遇到的问题@Bradley,您对这段代码何时会在ember latest中结束有任何预测吗?这非常有用,而且很可能会解决我现在在使用ember.run.next对dom元素执行代码时遇到的问题@布拉德利,你有没有预测这段代码最晚什么时候会在余烬结束?