2016-08-02 8 views
0

現在、流星のフレームワークを学んでいますが、今は私のコードがうまくいかない理由を理解できません。私は、新しいDate()を使用する "date"という変数を持つ "time"というテンプレートを作成しようとしています。私のHTMLファイルに日付と時刻を表示するが、動作していない。それが示すのは、時間を示すことなく「今の時」です。テンプレートヘルパーを使用して流星の時間と日付を表示

HTML::

<head> 
    <title>my_first_app</title> 
</head> 
<body> 
    <h1>Hello from Greece!</h1> 
    {{>time}} 
</body> 

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

Javascriptを:

import { Template } from 'meteor/templating'; 
import { ReactiveVar } from 'meteor/reactive-var'; 
import './main.html'; 

var date = new Date(); 

Template.time.helpers({ 
    time: function(){ 
    return new Date(); 
    } 
}); 

はここに私のHTMLとJSファイルです(私は私のコースが使用する最初のテンプレート画像のための同じロジック以下にそれを作ってみました)

答えて

2

テンプレートのヘルパー名を 'date'ではなく 'time'に変更するか、あいまいさを減らすためには次のようにする必要があります。

<head> 
    <title>my_first_app</title> 
</head> 
<body> 
<h1>Hello from Greece!</h1> 
{{>time}} 
</body> 
<template name="time"> 
    <p>The time now is {{timeVal}}</p> 
import { Template } from 'meteor/templating'; 
import { ReactiveVar } from 'meteor/reactive-var'; 

import './main.html'; 

var date = new Date(); 


Template.time.helpers({ 


timeVal: function(){ return new Date(); }});