SetTimeout与Ember.run.later在一个ember应用程序? [英] SetTimeout vs. Ember.run.later in an ember app?

查看:113
本文介绍了SetTimeout与Ember.run.later在一个ember应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 今天的日期:{{currentDate}} 
当前时间:{{currentTime

在我的助手里面:

  Ember.Handlebars.registerBoundHelper'currentDate',(选项) - > 
moment()。format('LL');

Ember.Handlebars.registerBoundHelper'currentTime',(选项) - >
moment()。format('h:mm:ss a');

如何每1秒更新一次currentTime到视图?



我已经阅读了Ember的建议 Ember.run.later ,但我无法确定哪里放置它,以及如何使用这个帮助器调用它。

解决方案

您可以像通常使用setTimeout一样使用ember.run.later

  Ember.run.later((function(){
//在这里执行的操作将在2秒内运行
}),2000);

我不是内部的,但我知道集成测试ember要求您使用run.later (如果您没有测试代码不会等待超时完成)


Inside my handlebars template:

Today's date: {{currentDate}}
Current Time: {{currentTime}}

Inside my helpers:

Ember.Handlebars.registerBoundHelper 'currentDate', (option) ->
  moment().format('LL');

Ember.Handlebars.registerBoundHelper 'currentTime', (option) ->
  moment().format('h:mm:ss a');

How would I go about updating the currentTime to the view every 1 second?

I have read the Ember recommends Ember.run.later but i can't quite figure out where to put it and how to call it using this helper.

解决方案

You can use ember.run.later like you would normally use setTimeout

Ember.run.later((function() {
  //do something in here that will run in 2 seconds
}), 2000);

I'm not of the internals but I know that integration testing ember requires that you use run.later (if you don't the test code won't wait for the timeout to finish)

这篇关于SetTimeout与Ember.run.later在一个ember应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆