【问题标题】:Meteor - Pagination流星 - 分页
【发布时间】:2017-05-25 12:26:42
【问题描述】:

我正在尝试使用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) 在 onMessage (http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:3385:12) 在http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:2736:11 在 Array.forEach (本机) 在 Function..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)

有什么想法我可能做错了吗?

【问题讨论】:

    标签: meteor


    【解决方案1】:

    确保代码

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

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

    【讨论】:

      【解决方案2】:

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

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

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

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

      这应该会为你解决问题

      【讨论】:

      • 当我这样做时:this.Pages = new Meteor.Pagination("tasks");,我收到错误:“'tasks' 集合是在 之外创建的。通过 构造函数的集合对象而不是集合的名称。[collection-inaccessible]"
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 2014-03-04
      • 2015-11-03
      • 2014-07-03
      相关资源
      最近更新 更多