Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Ember.js中,';后渲染';重画时不触发?_Javascript_Jquery_Ajax_Ember.js - Fatal编程技术网

Javascript 在Ember.js中,';后渲染';重画时不触发?

Javascript 在Ember.js中,';后渲染';重画时不触发?,javascript,jquery,ajax,ember.js,Javascript,Jquery,Ajax,Ember.js,我试图在视图中的表中添加新数据时调用一个函数,但它不起作用。我正在使用Ember.js2.5 我有两个模型,客户端和用户。客户机有许多用户 我列出客户端的视图如下所示: <table class="table table-striped" id="admin-table"> <thead> <tr> <th>Primary User</th> <th>User Email</th&g

我试图在视图中的表中添加新数据时调用一个函数,但它不起作用。我正在使用Ember.js2.5

我有两个模型,客户端和用户。客户机有许多用户

我列出客户端的视图如下所示:

<table class="table table-striped" id="admin-table">
  <thead>
    <tr>
      <th>Primary User</th>
      <th>User Email</th>
      <th>Join Date</th>
    </tr>
  </thead>
  <tbody>
    {{#each model as |client|}}
      <tr>
        <td>{{client.primaryUser.name}}</td>
        <td>{{client.primaryUser.email}}</td>
        <td>{{client.createdAt}}</td>
      </tr>

    {{/each}}
  </tbody>
</table>
问题 我正在使用jQueryTableSorter库,它向表中添加排序和筛选。因为主要用户get是由AJAX加载的,所以我需要在添加新数据时调用
$('#admin table').trigger('update')
,以便库索引新信息

以下是我正在做的:

  modelObserver: function() {
    Ember.run.next(this, this.updateTable);
  }.observes('model.@each.primaryUser')
我尝试了
run.next
run.scheduleOnce('afterRender')
,结果总是一样的。
updateTable
函数在呈现所有primaryUser对象之前触发

下面是如果我在
这个.updateTable中放置一个调试器会发生什么:

当呈现缓存的用户(me)时,它只触发一次。此表中的空单元格会在几毫秒后填充,此时剩余的用户信息会被压缩,但
updateTable
不会重新运行

此时,我可以确认其他主要用户字段不在DOM中:

帮助
渲染完所有对象后,是否有方法触发事件?我已经使用了中提到的
Ember.run.sync()
,但没有任何帮助。

一切正常,但您需要手动检查是否已呈现所有用户。别无选择。我想代码应该是这样的。这有点原始,但我想你会认为你可以检查DOM

modelObserver: function() {
    var areRendered = [];
    Ember.$('table#admin-table tr').each(function (index, element) {
        $(element).find('td').each(function (anotherIndex, anotherElement) {
            if (anotherIndex <= 1) { //This is because according to your screenshot you don't have to check all the cells, just first two if I'm not mistaking.
                if (anotherElement.text()) {
                    areRendered.push(true);
                } else {
                    areRendered.push(false);
                }
            }
        });
    });
    if (!areRendered.contains(false)) { //Checking if there were any element without data.
        Ember.run.next(this, this.updateTable);
    }
}.observes('model.@each.primaryUser')
modelObserver:function(){
变量areredered=[];
余烬。$('table#admin table tr')。每个(函数(索引,元素){
$(元素).find('td').each(函数(另一个索引,另一个元素){

if(anotherIndex)为什么不在需要更新表时设置一个条件呢?我的意思是像这样的smth
modelObserver:function(){if(/*这里需要检查是否所有用户都被呈现了*/){Ember.run.next(this,this.updateTable);}}。观察('model.@each.primaryUser')
modelObserver: function() {
    var areRendered = [];
    Ember.$('table#admin-table tr').each(function (index, element) {
        $(element).find('td').each(function (anotherIndex, anotherElement) {
            if (anotherIndex <= 1) { //This is because according to your screenshot you don't have to check all the cells, just first two if I'm not mistaking.
                if (anotherElement.text()) {
                    areRendered.push(true);
                } else {
                    areRendered.push(false);
                }
            }
        });
    });
    if (!areRendered.contains(false)) { //Checking if there were any element without data.
        Ember.run.next(this, this.updateTable);
    }
}.observes('model.@each.primaryUser')