0

私のアプリケーションは 500 ミリ秒ごとにデータをリロードします。500 ミリ秒ごとにリロードせず、最後のリロード後 500 ミリ秒待機して新しいリロードをトリガーするようにコードを変更するにはどうすればよいですか?

App = Ember.Application.create({
  ready: function() {
    var switchboard = App.Switchboard.find(switchboard_id);
    setInterval(function() {
      switchboard.reload();
    }, 500);
  }
});
4

1 に答える 1

0

私はちょうど似たようなことをしました。activateルートでプロパティを使用する必要があります ( http://emberjs.com/api/classes/Ember.Route.html#method_activate )。

このプル リクエストをチェックしてください: https://github.com/chrmod/rowmark/pull/2/files

いくつかの例:

App.NoteRoute = Ember.Route.extend({
  activate: function() {
    this.interval = setInterval(function() {
      this.get('controller').set('toSave', true);
    }.bind(this), 5000);
  }
})

アップデート

私はあなたが間違っていることを理解しています。そのために残念。

まず、findfromEmber Modelまたはreturn を知る必要がありEmber Dataますpromises( http://emberjs.com/blog/2013/05/28/ember-data-0-13.html )

私はあなたがそれを実装するためにそのようなトリックを行うことができると思います:

App = Ember.Application.create({
  ready: function() {
    var switchboard;
    setInterval(function() {
      switchboard = App.Switchboard.find(switchboard_id).then(function(){
        setTimeout(function(){}, 499);
      });
    }, 1);
  }
});

まず、setIntervalこれを infinity で実行するために実行しますloop。次に、各ループの繰り返しで、 に渡されて実行されるデータを外部サーバーからロードするSwitchboardときに、を見つけます。この関数は単に 499ms 待ちます:)Ember datafunctionthen

于 2013-06-23T19:40:54.723 に答える