【问题标题】:Why pivottable.js not working in Meteor project?为什么 pivottable.js 在 Meteor 项目中不起作用?
【发布时间】:2016-04-10 08:15:43
【问题描述】:

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

【问题讨论】:

    标签: jquery dom meteor pivottable.js


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-05-28
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 2020-12-27
      • 2023-03-31
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多