在 Ember.CollectionView 渲染结束时运行 jquery [英] Run jquery at the end of Ember.CollectionView rendering

查看:15
本文介绍了在 Ember.CollectionView 渲染结束时运行 jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ContainerView,其中包含一个 CollectionView.在此 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.

如果我在 CollectionViewdidInsertElement 中执行该 jquery,它可以工作,但它会针对 CollectionView 中的每个元素执行,而我真的只需要在最后完成一次.我该如何指定?

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();
​

推荐答案

执行此操作的功能最近才添加到 master 分支,因此您需要编译自己的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆