JQuery DataTable不适用于Meteor

MCh*_*han 2 jquery meteor jquery-datatables

我试图在我的Meteor项目中实现jQuery DataTables,但我总是收到以下错误.有人可以告诉我我在这里错过了什么/做错了吗?以下是我的Meteor应用程序代码.谢谢.

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)
Run Code Online (Sandbox Code Playgroud)

Project.html - 客户端文件夹

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

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

  </div>
</template>
Run Code Online (Sandbox Code Playgroud)

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"
    }
  };
};
Run Code Online (Sandbox Code Playgroud)

Server.js - 服务器文件夹

var ProjectsTable;
  ProjectsTable = new DataTableComponent({
    subscription: "dtProjects",
    collection: Projects
  });
  ProjectsTable.publish();
Run Code Online (Sandbox Code Playgroud)

Projects.js - 适用于服务器和客户端:

Projects = new Mongo.Collection('projects');
Run Code Online (Sandbox Code Playgroud)

MKM*_*MKM 5

根据流星话,JQuery dataTables复制了MiniMongo,Spark和Spacebars提供的大量排序和DOM操作功能.因此,即使您可以将样式整理出来(或决定忽略样式),排序和其他功能最终也不会像在DataTables下反应性地更新表时期望的那样.

话虽如此,2014年7月30日,Meteor Google支持小组中提到的流星jquery-datatables的创建者(menway - menway的创建者:jquery-datatables包分叉创建Meteor Datatable包):

使用jquery-datatables和meteor一起做复制功能和必须协调jquery-datatables dom状态和流星反应性有很多困难.

因此,检查另一个包或可能检查其他分页方法可能是个好主意:https://github.com/awatson1978/clinical-ui-crud-table

我个人会推荐Reactive Table https://github.com/ecohealthalliance/reactive-table.它非常稳定,易于实现/配置.

也可以看看: