1

タイマーを作成しようとしていますが、JavaScript ファイルは次のとおりです。

function timer(){
  var date = new Date();
  Template.pomodoro.timer = function() { return date};
  Template.pomodoro.message = function() { return "test message"};

} 


if (Meteor.isClient) {
      Meteor.setInterval( timer(), 1000 );
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup

  });
}

それらを同期させるために、すべてのブラウザーに同じタイマー (計算されたサーバー側) をプッシュしたいと考えています。

テンプレートは初回のみ更新されますが、毎秒更新されないのはなぜですか?

ありがとうフランチェスコ

4

2 に答える 2

2

試す:

if (Meteor.isClient) {
      Meteor.setInterval( function(){timer()}, 1000 );
}

または:

if (Meteor.isClient) {
      Meteor.setInterval( timer, 1000 );
}

これは、setInterval の最初の引数が関数ポインターである必要があり、それを使用()しているためです。これは、関数を渡す代わりに実行していることを意味します。

于 2013-04-17T08:40:10.790 に答える