在流星中的异步填充数据表上调用函数 [英] Calling a function on a table of async populted data in Meteor

查看:54
本文介绍了在流星中的异步填充数据表上调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Meteor和jquery数据表库。
我有一个表,我正在使用类似这样的东西来加载流星/把手:

I am using Meteor and the jquery data table library. I have a table that I am loading meteor/handlebars using something like this:

<table>
{{each x}}
  // code to insert rows of data
{{/each}}
</table>

一旦它已经完全填充了数据,就需要在表上调用它,将其转换为可排序表:

I need to call this on the table once it has been fully populated with data to turn it into a sortable table:

$('#tableID').dataTable();

当DOM完全加载并且数据在那里后,我从控制台调用它时,它可以工作,但使用Template.rendered()无效,也无法使用.observe监听更改,因为在呈现特定视图之前已加载数据。

It works when I call it from the console once the DOM is fully loaded and the data is in there, but using Template.rendered() doesn't work, nor does listening for changes with .observe since the data is loaded before that particular view is rendered.

在哪里可以我运行此代码来确保数据已完全加载,并且如果表中的数据有更新,它将再次运行?

Where can I run this code to ensure that the data is fully loaded, and if there are updates to the data in the table that it will run again?

推荐答案

我找到了一种方法,在将各个行拆分为模板后,它似乎可以工作-随着我继续对其进行调试,它会不断更新(这当然不理想)。

I found a way of doing it which seems to work after I split the individual rows into templates - will update as I continue to debug it (and this is certainly not ideal).

Template.individualRow.rendered = function() {
  if (!$('#tableID').hasClass('initialized')) {
      $('#tableID').not('.initialized').addClass('initialized').dataTable();
  };
};

这篇关于在流星中的异步填充数据表上调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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