在我的 Handlebars 模板内:
Today's date: {{currentDate}}
Current Time: {{currentTime}}
在我的助手内部:
Ember.Handlebars.registerBoundHelper 'currentDate', (option) ->
moment().format('LL');
Ember.Handlebars.registerBoundHelper 'currentTime', (option) ->
moment().format('h:mm:ss a');
我如何每 1 秒更新一次 View 的 currentTime ?
我已阅读 Ember 推荐 Ember.run.later
但我不太清楚该把它放在哪里以及如何使用这个助手来调用它。
最佳答案
您可以像通常使用 setTimeout 一样使用 Ember.run.later
Ember.run.later((function() {
//do something in here that will run in 2 seconds
}), 2000);
我不确定内部结构,但我知道集成测试 Ember 要求您使用 run.later (如果您不这样做,测试代码将不会等待超时完成)。
关于ember.js - Ember 应用程序中的 SetTimeout 与 Ember.run.later?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21505332/