简体   繁体   English

数据加载时的余烬视图事件

[英]ember view event when data loaded

I have this Ember View code: 我有这个Ember View代码:

{{#view "tabla"}}
    <table>
        ...
    </table>
{{/view}}

and I need to run a javascript code to the HTML table after the data from an asynchronous call is rendered. 在呈现异步调用的数据后,我需要在HTML表中运行JavaScript代码。

I tried to do this: 我试图这样做:

App.TablaView = Ember.View.extend({
didInsertElement : function() {
    Ember.run.scheduleOnce('afterRender', this, function() {
       javascript code..
     });
 }

but it is executed when the table is rendered without data. 但是在没有数据的情况下渲染表时执行。

I also tried to call the javascript code in the callback of my asynchronous function, but the data was not rendered to the view yet. 我还尝试在异步函数的回调中调用javascript代码,但是数据尚未呈现到视图中。

Is there any event triggered after the binding is executed? 绑定执行后是否触发任何事件?

Thanks! 谢谢!

I had somewhat the same issues and I ended up fixing it like this: 我遇到了一些相同的问题,最终像这样修复它:

didInsertElement: function() {
    _this = this;
    if (this.get('element').addEventListener) {
       this.get('element').addEventListener ('DOMNodeInserted', function() {
          Ember.run.scheduleOnce('afterRender', _this, function() {
              javascript code..
          });
       }, false);
    }
   //for images
   $( "img",this.$()).load(function() {
   Ember.run.scheduleOnce('afterRender', _this, function() {
          javascript code..
     });
   });
}

be aware that in this solution your "javascript code.." code could be called (and executed) multiple times. 请注意,在此解决方案中,您的“ javascript代码..”代码可以多次调用(并执行)。 That wasn"ta problem in my case but it could be an issue in yours. 在我看来,这不是问题,但对您来说可能是个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM