简体   繁体   English

我的简单流星代码出了什么问题

[英]What is wrong with my simple meteor code

When I run it, nothing displays in the browser. 当我运行它时,浏览器中没有任何内容。 HTML: 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: JS:

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

if (Meteor.isServer) {

}

Im new to meteor pls bear with me. 我是流星的新手,请耐心等待。 This code is for displaying the time currently. 此代码用于显示当前时间。 Help appreciated, thanks 帮助表示感谢,谢谢

Try by seperating your template from your body html. 尝试从您的身体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>

You are defining the Helpers the wrong way. 你正在以错误的方式定义助手。 Try: 尝试:

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

you forgot you libery of meteor.js, you should include it in your head 你忘记了meteor.js的libery,你应该把它包含在你的head

example is below 示例如下

codepen codepen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM