Saturday 22 June 2013

Call a Function after specific duration in Sencha Touch 2

Today, i am going to explain the important method available in sencha touch 2, i.e Ext.defer()
This method will execute the function after the number of milliseconds specified. It accepts these below parameters
  • fn : The function to execute.
  • millis : The number of milliseconds after the function will execute. If less than or equal to 0 the function is executed immediately.
  • scope (optional) : scope of the function. If omitted, defaults to the browser window.
  • args (optional): Overrides arguments for the call. Defaults to the arguments passed by the caller.
  • appendArgs (optional): if true, args are appended to call args instead of overriding, if a number the args are inserted at the specified position.

Let's see an implementation, we are going to load a store after 1 seconds.
Ext.defer(function() {

   var mystore = Ext.getStore('#storeid');
   mystore.load();

}, 1000, this);


This method works similar to setTimeout() method in Javascript.

Usage:
  • This method will be used to execute an action after specific duration, mainly in asynchronous function call.
  • If you need to reload the view components (container, panel, list, dataview etc) after specific duration.
Hope, you enjoyed this Post.

No comments:

Post a Comment