我的简单meteor代码有什么问题?

3
当我运行它时,浏览器中没有显示任何内容。 HTML:
<head>
<title>projectsiddharth</title>
</head>
<body>
<h1>Hello from india!</h1>
<div class="java">{{> timetemplate}}</div>
<template name="timetemplate">
<p>The time is now {{time}}</p>
</template>
</body>

JS:

if (Meteor.isClient) {
var data = {time: new Date()};
Template.timetemplate.helpers(data);
}

if (Meteor.isServer) {

}

我是meteor的新手,请多多包涵。这段代码用于显示当前时间。需要帮助,谢谢。


1
嗨,我不使用Meteor,但Meteor教程网站上的示例显示模板标记为外部而非内部,不确定这是否会影响您的结果。【示例】(https://www.meteor.com/tutorials/blaze/templates) - AranDG
@AranDG 哈哈,我太傻了。现在它能用了。非常感谢你兄弟:) 是我不好哈哈。 - Siddharth Venu
1
@Siddarth 不用担心,我相信 @K Ф 已经在下面发布了同样的解决方案作为答案。由于我没有 Meteor 进行测试,所以无法发布答案。请确保他们得到声望,因为他们无疑已经调试过了。 - AranDG
3个回答

4
尝试将模板与正文HTML分离。
<head>
 <title>projectsiddharth</title>
</head>
<body>
 <h1>Hello from india!</h1>
 <div class="java">{{> timetemplate}}</div>
</body>

<template name="timetemplate">
 <p>The time is now {{time}}</p>
</template>

1
您正在错误地定义Helpers。请尝试以下代码:

if (Meteor.isClient) {
    Template.timetemplate.helpers({
        time: function(){
            return new Date();
        };
   });
}

我不同意。我有一个Meteor项目,我使用了Date()函数并且能够在我的模板中通过{{time}}显示时间。 - kemicofa ghost
先生,它说 '=> 错误阻止了启动: 在处理 ecmascript 文件时(针对 web.b 目标项目) projectsiddharth.js:4:18: projectsiddharth.js: 意外 在处理 ecmascript 文件时(针对 os.win 目标项目) projectsiddharth.js:4:18: projectsiddharth.js: 意外=> 您的应用程序存在错误。正在等待文件更改。' - Siddharth Venu
@Siddarth Venu 或许这个链接可以帮助你解决这个错误 https://github.com/meteor/meteor/issues/5551 - coder14

0

你忘记了meteor.js库,应该在你的head中引入它。

以下是示例:

codepen


先生,我以前使用过Meteor,但没有包含Meteor js文件。附注:我在命令提示符中编译它,所以不需要包含它。 - Siddharth Venu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接