首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Meteor在使用flowrouter时抛出错误"Exception in defer callback: Error: Can't call non-function:[object Object]“

问Meteor在使用flowrouter时抛出错误"Exception in defer callback: Error: Can't call non-function:[object Object]“
EN

Stack Overflow用户
提问于 2016-06-28 20:25:26
回答 2查看 1.6K关注 0票数 3

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

所以我的项目文件是:

/lib/router.js:

代码语言:javascript
复制
FlowRouter.route("/", {
    name: 'home',
    action(){
        BlazeLayout.render("HomeLayout");
    }
});

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

/imports/ui/layouts/HomeLayout.html:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<template name="MainLayout">
    <header>
        <h1>My Recipe Book</h1>
        {{> loginButtons}}
    </header>
    <main>
        {{ Template.dynamic template=main }}
    </main>
</template>

/imports/ui/pages/TestPage.html:

代码语言:javascript
复制
<template name="TestPage">
    I am a test....
</template>

/client/main.js:

代码语言:javascript
复制
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时,我得到了以下错误:

代码语言:javascript
复制
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)

这在视频教程中工作得很好,视频教程来自level up tuts,它也很出名。但正如我所说,它是在旧版本的流星上,所以没有es6。我使用的meteor版本是1.3.4.1。

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

EN

回答 2

Stack Overflow用户

发布于 2016-06-28 23:02:23

哦,找到问题了。{{Template.dynamic template=main}}的把手语法中缺少右尖括号。应该是{{> Template.dynamic template=main}}

票数 3
EN

Stack Overflow用户

发布于 2016-06-28 20:43:54

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38076231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档