我正在开发一个简单的聊天应用程序,当我点击REFRESH按钮时,我可以查看更新的数据,但是我可以从服务器定期刷新数据(因为我的聊天远程存储在数据库中)自动刷新Sencha Touch应用程序中的列表
在此先感谢。
我正在开发一个简单的聊天应用程序,当我点击REFRESH按钮时,我可以查看更新的数据,但是我可以从服务器定期刷新数据(因为我的聊天远程存储在数据库中)自动刷新Sencha Touch应用程序中的列表
在此先感谢。
使用DelayedTask类煎茶触摸的:
//create the delayed task instance with our callback
var task = Ext.create('Ext.util.DelayedTask', function() {
//load the list's store here. The list will be automatically updated
listComp.getStore().load(); // Assuming your list component is "listComp"
listComp.refresh();
// The task will be called after each 10000 ms
task.delay(10000);
}, this);
//The function will start after 0 milliseconds
//so we want to start instantly at first
task.delay(0);
//to stop the task, just call the cancel method
//task.cancel();
这应该为你的情况下工作。
你只需要在正常的权利调用你的refresh()函数?
所以你只需要在你的refresh()
函数的末尾添加一个setTimeout("refresh()", 1000);
。然后你只需要在你的应用程序启动时调用它。
希望这有助于
你好,让我把这个添加到我的代码中,如果我需要任何进一步的帮助,我会回复给你。谢谢... – 2012-03-14 07:44:35
也许您会对聊天应用程序中的套接字服务器连接感兴趣。每当服务器数据发生变化时,服务器都会通知客户看看http://socket.io/
请看看这个。 它会调用每个(您设置的时间)的函数。 http://www.sencha.com/forum/showthread.php?194202-Autorefresh-List-with-DelayedTask
谢谢。试了一下,并在建议的片段中进行了一些调整,使我的工作得到了正确执行。谢谢.... – 2012-03-26 10:43:13
我已经做了上面的例子任务。任务在主控制器中初始化,但切换到另一个视图后,正在运行的任务被取消。我是否需要添加其他特定配置? – 2013-02-20 11:06:45
Peter O.任务只会在你放入task.cancel(); 试着看看这里的例子。 (http://www.sencha.com/forum/showthread.php?194202-Autorefresh-List-with-DelayedTask)它对我来说很好。我想你也会。 – 456qwe123asd 2013-10-24 13:04:05