最近几天我研究meteor js框架,我想为meteor编写一个包,但是当我尝试一个包时,我有一个关于模板的问题
在我的package.js
中 api.use([
'templating',
"coffeescript",
], "client");
api.addFiles([
'client/breadcrumb.coffee',
'client/helpers.coffee',
'client/views/breadcrumb/crumb.html'
], 'client');
api.use(['coffeescript'], 'server');
api.addFiles('server/breadcrumb.coffee', 'server');
在我的helper.coffee中我使用这样的代码片段:
Template.breadcrumbs.helpers ->
crumbs: () ->
Breadcrumb.getCrumbs()
当我在我的应用程序中包含我的软件包时,它无效。 这是错误:
Uncaught ReferenceError: Template is not defined helpers.coffee:1
Uncaught TypeError: Cannot read property 'Breadcrumb' of undefined global-imports.js:13
Uncaught ReferenceError: Template is not defined template.dashboard_category.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_contact.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_contact_detail.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_post.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_post_form.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_user.js:2
Uncaught ReferenceError: Template is not defined template.about.js:2
Uncaught ReferenceError: Template is not defined template.contact.js:2
Uncaught ReferenceError: Template is not defined template.dashboard.js:2
Uncaught ReferenceError: Template is not defined template.home.js:2
Uncaught ReferenceError: Template is not defined template.dashboard.js:2
Uncaught ReferenceError: Template is not defined template.layout.js:2
Uncaught ReferenceError: Template is not defined template.404.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_breadcrumb.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_header.js:2
Uncaught ReferenceError: Template is not defined template.dashboard_slidebar.js:2
Uncaught ReferenceError: Template is not defined template.flash.js:2
Uncaught ReferenceError: Template is not defined template.footer.js:2
Uncaught ReferenceError: Template is not defined template.header.js:2
Uncaught ReferenceError: Template is not defined template.loading.js:2
Uncaught ReferenceError: Deps is not defined dashboard_category.coffee.js:2
Uncaught ReferenceError: Deps is not defined dashboard_contact.coffee.js:2
Uncaught ReferenceError: Deps is not defined dashboard_post.coffee.js:2
Uncaught ReferenceError: Meteor is not defined dashboard_user.coffee.js:2
Uncaught ReferenceError: Template is not defined dashboard.coffee.js:2
Uncaught ReferenceError: Meteor is not defined client.coffee.js:2
Uncaught ReferenceError: Meteor is not defined collections.js:3
Uncaught ReferenceError: SimpleSchema is not defined schema.js:6
Error: Spacebars is not defined
ReferenceError: Spacebars is not defined
at null._render (http://localhost:3000/packages/accounts-ui-unstyled.js?724142103f86896bf7ab0a57672b34086f989b24:634:12)
at doRender (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1853:25)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1795:16
at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:2029:12)
at viewAutorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1794:18)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:476:11)
at Blaze.View.autorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1793:19)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1847:10
> Before: 630ms (diff: 630ms)
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:738:12
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:774:4
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:1022:3
> Before: 676ms (diff: 46ms)
at Array.forEach (native) reporters.js?1413185929295:67
Error: Exception in defer callback:
ReferenceError: Spacebars is not defined
at null._render (http://localhost:3000/packages/iron_layout.js?080dc95e770e3130757bf6af69fd0abb99573ae4:95:10)
at doRender (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1853:25)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1795:16
at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:2029:12)
at viewAutorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1794:18)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:476:11)
at Blaze.View.autorun (http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1793:19)
at http://localhost:3000/packages/blaze.js?7b7ff7ee2ccdccd85a1ad0d8dc9d96193e29e8b0:1847:10
> Before: 657ms (diff: 657ms)
at usePostMessage (http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:376:12)
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:405:3
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:410:4
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:1022:3
答案 0 :(得分:2)
这只是一个加载顺序问题:Meteor要求必须在Spacebars中声明模板,然后才能引用它以在JS中定义其助手。
通过在源文件列表中声明您希望在JS对应项之前加载Spacebars HTML,您的错误应该消失。
api.addFiles([
'client/views/breadcrumb/crumb.html',
'client/helpers.coffee',
'client/breadcrumb.coffee'
], 'client');