简体   繁体   English

jQuery DataTable不适用于流星

[英]JQuery DataTable not working on Meteor

I am trying to implement jQuery DataTables in my Meteor project, but I am always getting the following error. 我试图在我的Meteor项目中实现jQuery DataTables ,但是我总是遇到以下错误。 Can someone please tell me what I am missing / doing wrong here? 有人可以告诉我我想念什么/做错了吗? Below is my Meteor app code. 以下是我的Meteor应用程式程式码。 Thanks. 谢谢。

Uncaught TypeError: Cannot set property 'pagesData' of undefined underscore.js:848
Error: Exception from Tracker recompute function:
Error: Can't call non-function: undefined
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?cb20740019f26bdca2faa89ba9c973f618118521:172:13)
    at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?cb20740019f26bdca2faa89ba9c973f618118521:106:25)
    at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?cb20740019f26bdca2faa89ba9c973f618118521:110:39)
    at null._render (http://localhost:3000/packages/jquery-datatables.js?bf10e73db3f8b2f4afdc77c33ba3c62092556ae7:1010:22)
    at doRender (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1853:25)
    at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1795:16
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:2029:12)
    at viewAutorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1794:18)
    at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
    at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)

Project.html - Client folder Project.html-客户端文件夹

<template name="projectslist">
  <div class="projectslist">

    <div>
        {{> DataTable dtProjects }}
    </div>

  </div>
</template>

Projectlist.js - Client folder Projectlist.js-客户端文件夹

Template.projectslist.dtProjects =  function() {    
  return {
    id: "my-unique-table-id",
    columns: [
      {
        title: "Name",
        data: "name"
      }, {
        title: "Description",
        data: "description"
      }, {
        title: "Delivery Date",
        data: "deliverydate"
      }
    ],
    subscription: "dtProjects",
    query: {
      grade: "A"
    }
  };
};

Server.js - Server Folder Server.js-服务器文件夹

var ProjectsTable;
  ProjectsTable = new DataTableComponent({
    subscription: "dtProjects",
    collection: Projects
  });
  ProjectsTable.publish();

Projects.js - Available for both Server and Client: Projects.js-服务器和客户端均可使用:

Projects = new Mongo.Collection('projects');

As per meteor-talk , JQuery dataTables duplicates a lot of the sorting and DOM manipulation functions that MiniMongo, Spark, and Spacebars provide. 根据流星对话 ,JQuery dataTables复制了MiniMongo,Spark和Spacebars提供的许多排序和DOM操作功能。 So even if you can get the styling sorted out (or decided to ignore styling), sorting and other functions wind up not behaving like one is expecting when the table reactively updates underneath DataTables. 因此,即使可以整理出样式(或决定忽略样式),排序和其他功能也会出现异常,就像表在DataTables下进行反应性更新时所期望的那样。

Having said so, on July 30, 2014 Austin Rivas, the creator of the meteor-jquery-datatables (which menway - creator of the menway:jquery-datatables package forked to create the Meteor Datatable package) mentioned in Meteor Google support groups: 话虽这么说,但在2014年7月30日,奥斯汀·里瓦斯(Austin Rivas),在Meteor Google支持小组中提到了meteor-jquery-datatables的创建者(menway- menway:jquery-datatables包的创建者创建了Meteor Datatable包)。

There are lots of difficulties with using jquery-datatables and meteor together do to duplicate functionality and having to reconcile jquery-datatables dom state with meteor reactivity. 使用jquery-datatables和meteor一起做以复制功能以及必须协调jquery-datatables dom状态与流星反应性存在很多困难。

So it might be a good idea to check another package or possibly check alternative approaches for pagination: https://github.com/awatson1978/clinical-ui-crud-table 因此,检查另一个软件包或检查分页的替代方法可能是一个好主意: https : //github.com/awatson1978/clinical-ui-crud-table

Personally I would recommend Reactive Table https://github.com/ecohealthalliance/reactive-table . 我个人建议使用Reactive Table https://github.com/ecohealthalliance/reactive-table It is quite stable, easy to implement / configure. 它相当稳定,易于实现/配置。

See also: 也可以看看:

  1. Remove the mrt version: 删除mrt版本:

    mrt remove jquery-datatables

  2. Add the Meteor 0.9+ version: 添加Meteor 0.9+版本:

    meteor add menway:jquery-datatables

However, it seems like it is still not 0.9 compatible as package.js still uses spacebars. 但是,由于package.js仍使用空格键,因此似乎仍不兼容0.9。 Give it a shot, though. 不过试一试。

Maybe it's worth looking at this extension instead: https://atmospherejs.com/ephemer/reactive-datatables 也许值得看看此扩展: https : //atmospherejs.com/ephemer/reactive-datatables

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

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