The classes that support multithreading in ExtJs are Ext.util.TaskRunner and Ext.util.DelayedTask. Taskrunner provides multi-threaded timing services, Delayedtask allows you to delay how long to perform a task in a new thread. Ext.taskmgr is a Taskrunner instance, the last line in Taskmgr.js source code can be seen:
Ext.taskmgr = new Ext.util.TaskRunner ();
Essentially, whether they are taskrunner or delayedtask, they perform tasks through setinterval (), Taskrunner can repeatedly execute a method, and Delayedtask is called after a task is delayed. Clearinterval () to ensure that it is executed only once. So here's how to pass parameters to a task's run () method, which is essentially passing parameters to the SetInterval () method.
We went to http://extjs.com/deploy/dev/docs/output/Ext.util.TaskRunner.html to see the task in Taskrunner's Api,start (Object Task) A parameter is a configuration object that focuses on its two properties:
Run:function method of timing execution
Args:array the arguments passed to the Run method above
To see a basic use method, here is the use without the args attribute parameter:
01.Ext.onReady(function(){
02. var runner = new Ext.util.TaskRunner ();
03. runner.start({ //任务被调用的方法
04. run: function(){
05. alert('run() 方法被执行.')
06. },
07. interval: 1000, //一秒执行一次
08. repeat: 5 //重复执行 5 次
09. });
10.});
Instead of providing parameters to the run () method, how do you pass the parameters to run (), and how do the run () method get the incoming parameters? The method is: The intrinsic attribute of JS function arguments. Look at the code:
01.Ext.onReady(function(){
02. var runner = new Ext.util.TaskRunner ();
03. runner.start({ //任务被调用的方法
04. run: function(){ //run 方法原型不变,实际可以去遍历这个 arguments 参数数组
05. alert('run() 方法被执行. 传入参数个数:' + arguments.length + ", 分别是: "
06. + arguments[0] +"," + arguments[1] +"," + arguments[2]);
07. return false; //不返回 false,run() 方法 会被永无止境的调用
08. },
09. args:[100,200,300],
10. interval: 1000, //一秒执行一次,本例中 run() 只在 1 秒后调用一次
11. repeat: 2 //重复执行 2 次, 这个参数已不再启作用了
12. });
13.});