如何定期更新Ember的模型(如在setInterval的)? [英] How to update Ember's model periodically (such as in setInterval)?

查看:232
本文介绍了如何定期更新Ember的模型(如在setInterval的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个灰烬应用程序的模型来自Ajax调用。第一次调用的伟大工程,我有Ember.Route模型挂钩返回一个承诺,Ajax调用来检索要显示的数据。

I have an Ember application whose model comes from an Ajax call. The first call works great, I have the model hook of the Ember.Route return a promise to the Ajax call that retrieves the data to be displayed.

但这个数据经常变化,在后台,我想有Web应用程序服务器轮询周期,也就是说,每5秒,并更新或,甚至更好,完全交换模型数据与新检索之一。

But this data changes frequently in the backend, and I want to have the webapp poll the server periodically, say, every 5 seconds, and update or, even better, swap the model data entirely with the newly retrieved one.

什么是做与Emberjs?适当的方式

我是新来的灰烬让我有点这个失去了...

I'm new to Ember so I'm a bit lost with this...

推荐答案

如果您不使用烬数据,你可以简单地添加一个递归的setTimeout 的setInterval 在您控制器并设置模式属性。简单的例子设置从UI事件模型 http://emberjs.jsbin.com/hacir/1/编辑

If you are not using ember-data you can simply add a recursive setTimeout or setInterval in you controller and set the model property. Simple example setting the model from a ui event http://emberjs.jsbin.com/hacir/1/edit .

如果您使用的是灰烬数据我认为下面的线程有更准确的解决方案

If you are using ember-data i think the following threads have more accurate solutions

区间灰烬模式重装

<一个href="http://stackoverflow.com/questions/14181223/how-to-reload-an-ember-data-record/14183507#14183507">How重装灰烬数据记录?

这篇关于如何定期更新Ember的模型(如在setInterval的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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