【问题标题】:Meteor JS alethes_pages.js:601 Uncaught TypeError: Cannot read property 'helpers' of undefinedMeteor JS alethes_pages.js:601 Uncaught TypeError: Cannot read property 'helpers' of undefined
【发布时间】:2015-04-23 10:37:30
【问题描述】:

错误:alethes_pages.js:601 Uncaught TypeError: Cannot read property 'helpers' of undefined

我是 Meteor Js 的新手。我在实现 alethes-pages 包时遇到了上述错误。

我已经实现了基本设置。没什么特别的。

以下代码位于“both”文件夹中。

Pages = new Meteor.Pagination('testCategory', {
    router: "iron-router",
    homeRoute: ["/", "/items/"],
    route: "/items/",
    routerTemplate: "War-id",
    routerLayout: "AdminLayout"
});


Pages.set({
    perPage: 10,
    sort: {
        category: -1
    }
});

以下是模板:

    <template name="War-id">

This is War-id Template......

    {{> pages }}

  {{> pagesNav}}

</template>

文本显示正确,但页面模板未显示

我在我的工作文件夹中运行了命令“流星更新”,所以所有内容都是最新版本(2014 年 12 月 18 日)

谁能指导我出了什么问题以及如何纠正它。

【问题讨论】:

  • 能否将该代码上传到meteorpad.com?或在 Nitrous.io 上制作一些随机框,这将很高兴为您提供帮助
  • 你的助手是在哪里定义的?

标签: javascript node.js meteor


【解决方案1】:

Meteor 对模板名称中的字符 - 不是很好,因为 javascript syntax rules 与变量名称有关。

改用下划线:

<template name="war_id">

</template>

然后在您的代码中使用Template.war_id.helpers 而不是Template.War-id.helpers 并将routerTemplate: "War-id" 重命名为routerTemplate: "war_id"

【讨论】:

  • 我也试过了,甚至去掉了_,-并使用了Warid,但问题依然存在。
  • 问题来自代码中的一行脚本,例如Template.xx.helpers,您有这行但没有相应的模板。你没有提到上面的代码,但那将是寻找问题的第一个地方。
【解决方案2】:

似乎你定义你的包的顺序,在我的 package.js 中,我把我用来调用 new Meteor.Pagination 的公共文件放在最后,所以依赖的模板(我称之为 {{> pages}} ...可以在 Pages.coffee 运行之前加载并且它可以工作:D

this.Pages = new Meteor.Pagination({
  templateName: "yourTemplateName",
  ...
});

api.add_files([
    'lib/common/pagination/common.js'
  ], ['client', 'server']);

【讨论】:

    猜你喜欢
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2019-02-12
    • 2021-09-20
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多