问题
I am developing an simple Chat Application, I can view the updated data when I click on the REFRESH Button, BUT can I refresh the data at a regular interval from the Server (as my Chat is getting Stored in the Database remotely)
Thanks in advance.
回答1:
Use DelayedTask class of Sencha Touch:
//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();
This should work for your case.
回答2:
You just need to call your refresh() function at a regular right ?
So you just need to add a setTimeout("refresh()", 1000);
at the end of your refresh()
function. Then you just need to call it when your app startup.
Hope this helps
回答3:
Maybe you'll be interested in socket server connection in your chat application. Server will notify your clients whenever server data changes. Take a look at http://socket.io/
回答4:
please look at this. It will call the function for every (time you set). http://www.sencha.com/forum/showthread.php?194202-Autorefresh-List-with-DelayedTask
来源:https://stackoverflow.com/questions/9697434/auto-refresh-the-list-in-sencha-touch-application