流星 - 分页

时间:2017-01-10 21:17:59

标签: meteor

我正在尝试使用meteor-pages。在我的JavaScript代码中,我有:

Tasks = new Mongo.Collection("tasks");

Tasks.attachSchema(new SimpleSchema({
  title: {
    type: String,
    label: "Title",
    max: 200
  },
  complete: {
    type: Boolean,
      defaultValue: false,
    label: " ",
      autoform: {
          type: "boolean-checkbox"
      }
  },
  dueDate: {
    type: Date,
    label: "Due Date",
    optional: true,
      autoform: {
        type: "pickadate"
    }
  }
}));

Pages = new Meteor.Pagination(Tasks, {
  templateName: "tasksPaginated"
})

在我的HTML中,我有:

<template name="TaskList">
    Before
    {{> tasksPaginated}}
    After
</template>

    <template name="tasksPaginated">
        {{> pages}}
        {{> pagesNav}}  Bottom navigation
    </template>

当我尝试浏览页面时,出现以下错误:

  

提供调用'pages_tasks / CountPages'的结果时出现异常:   错误       在Connection._livedata_result(http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:4736:23)       at onMessage(http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:3385:12)       在http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:2736:11       at Array.forEach(native)       在函数。 .each。 .forEach(http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:149:11)       在SockJS.self.socket.onmessage(http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:2735:11)       在SockJS.REventTarget.dispatchEvent(http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:175:22)       在SockJS._dispatchMessage(http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:1160:10)       在SockJS._didMessage(http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:1218:18)       在WebSocket.that.ws.onmessage(http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:1365:17

任何想法我可能做错了什么?

2 个答案:

答案 0 :(得分:0)

meteor-pages的文档说你可以像这样初始化它:

this.Pages = new Meteor.Pagination("tasks");

这将自动选择一个名为&#34; tasks&#34;的模板。另一种方式(我认为你想要的)是指定一个不同的模板,在这种情况下你的代码应该是:

this.Pages = new Meteor.Pagination("tasks", {itemTemplate: "tasksPaginated"});

那应该为你解决

答案 1 :(得分:0)

确保代码

Pages = new Meteor.Pagination(Tasks, {
    templateName: "tasksPaginated"
})

在您的Template.tasksPaginated全球可用之前不要运行