我想顯示當前日期。我已經寫了下面的代碼,但它並沒有顯示value
變量的值。在流星中顯示當前日期
<head>
<title>my_first_app</title>
</head>
<body>
<h1>Hello from Pakistan</h1>
{{> hello}}
{{> date}}
</body>
<template name="hello">
<button>Click Me</button>
<p>You've pressed the button {{counter}} times.</p>
</template>
<template name="date">
<p>The time now is {{value}}.</p>
</template>
JS:
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
Template.hello.helpers({
counter: function() {
return Session.get('counter');
}
});
Template.hello.events({
'click button': function() {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
}
});
var value = new Date();
Template.date.helpers(value);
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
}
你必須提供一個對象到'helpers'功能...'Template.date.helpers({值:值} )'甚至是'Template.date.helpers({value})'在ES6中。 –