0

pivottable.js 就像一个魅力,但不是在最基本的流星项目中。有html:

<body>
  <div id="output"></div>
</body>

js(出勤变量已定义,并且在非流星项目中一切正常):

$('#output').pivot(attendance,
  {
    rows: ["group", "trainer", "client"],
    cols: ["came"]
  }
);

在 Meteor 项目中,pivot.js 应按原样放置在 client/compatibility 文件夹中,并且加载顺序正确:jquery > pivot.js > my js code。得到错误:

pivot.js:949

Uncaught TypeError: Cannot read property 'hasChildNodes' of undefined
$.fn.pivot @ pivot.js:949
(anonymous function) @ sandbox.js:20
(anonymous function) @ sandbox.js?64df4e0c48aa567cada8bd4c28bd682ed2d9ab36:41
4

1 回答 1

0

Meteor 模板的工作方式略有不同。当它运行时,DOM 还没有被渲染。为了实现这一点,您必须在该模板呈现的回调中加载依赖于模板内的 DOM 的任何外部库。在这种情况下:

Template.body.rendered = function() {
$('#output').pivot(attendance,
  {
    rows: ["group", "trainer", "client"],
    cols: ["came"]
  }
);
}
于 2016-01-06T11:01:49.333 回答