【问题标题】:Meteor throws error "Exception in defer callback: Error: Can't call non-function: [object Object]" when using flowrouterMeteor 在使用 flowrouter 时抛出错误“延迟回调中的异常:错误:无法调用非函数:[object Object]”
【发布时间】:2016-10-30 18:46:26
【问题描述】:

我是流星新手,正在学习视频教程。问题是这个视频教程没有完全使用 ES6。所以没有进出口。但我正在使用 es6 功能制作我的流星应用程序,特别是模块的导入和导出。

所以我的项目文件是:

/lib/router.js:

FlowRouter.route("/", {
    name: 'home',
    action(){
        BlazeLayout.render("HomeLayout");
    }
});

FlowRouter.route("/test", {
    name: 'test',
    action(){
        BlazeLayout.render("MainLayout",{ main: "TestPage" });
    }
});

/imports/ui/layouts/HomeLayout.html:

<template name="HomeLayout">
    <header>
        <h1>My Recipe Book</h1>
        {{> loginButtons}}
    </header>
    <main>
        <div class="billboard">
            <h4>Organise your meals</h4>
        </div>
    </main>
</template>

/imports/ui/layouts/MainLayout.html:

<template name="MainLayout">
    <header>
        <h1>My Recipe Book</h1>
        {{> loginButtons}}
    </header>
    <main>
        {{ Template.dynamic template=main }}
    </main>
</template>

/imports/ui/pages/TestPage.html:

<template name="TestPage">
    I am a test....
</template>

/client/main.js:

import { Template } from 'meteor/templating';

import '/lib/router.js';

import '/imports/ui/layouts/MainLayout.html';
import '/imports/ui/layouts/HomeLayout.html';
import '/imports/ui/pages/TestPage.html';

我正在使用的软件包:

1- BlazeLayout

2- 流路由器

3- 帐号-ui

4- 账户密码

现在我的问题是,当我打开 localhost:3000 时,我看到我的 HomeLayout 符合预期。但是当我转到 localhost:3000/test 时,出现以下错误:

Exception in defer callback: Error: Can't call non-function: [object Object]
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=65db8b6a8e3fca189b416de702967b1cb83d57d5:175:13)
    at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?hash=65db8b6a8e3fca189b416de702967b1cb83d57d5:106:25)
    at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?hash=65db8b6a8e3fca189b416de702967b1cb83d57d5:110:39)
    at ._render (http://localhost:3000/app/app.js?hash=9b7bb2e95b10af20d691075d259b8ad46bc15c1d:55:22)
    at doRender (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2027:25)
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1875:20
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3687:12)
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1873:29
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2214:12)
    at viewAutorun (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1872:18)

这在视频教程中效果很好,视频教程是从升级的 tuts 开始的,它也很有名。但正如我在旧版本的流星上所说的,所以没有 es6。我使用的流星版本是1.3.4.1。

请帮我解决这个问题,因为我被困在这里无法取得进展。

【问题讨论】:

  • 你添加ecmascriptmeteor包了吗?
  • @pahan - 当然是的

标签: meteor meteor-blaze flow-router


【解决方案1】:

哦,找到问题了。在 {{Template.dynamic template=main}} 的车把语法中遗漏了一个封闭的尖括号。应该是 {{> Template.dynamic template=main}}

【讨论】:

    【解决方案2】:

    您不需要在main.js 文件中导入和导出。 Meteor 为您完成所有这些工作。你可以删除main.js

    相反,只需将模板 html 文件放在 client 目录中即可。 Meteor 会自动检测到它们,您的路由器将能够访问它们。

    【讨论】:

    • 那样我就无法正确安排我的项目。我将它们放在我的导入文件夹中的主要原因是我可以清楚地将不同的页面分隔在不同的文件夹中。稍后我可能不会使用特定模板,或者我可能不想为特定用户权限导入一些模板。
    • 您可以根据需要将模板放在client 内的不同目录中,例如client/views/layoutsclient/views/pages,
    猜你喜欢
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 2017-08-11
    • 2016-03-20
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多