开发者

Why excess args are passed to this.on function in extjs?

Inside a particular component, this is the existing code that I see:

this.on(开发者_Go百科'afterrender',function(cmp){
this.somePanel.someTabPanel.setAsUnSelected(); 
},this);

My questions are: What is cmp? It is not a std thing like btn or e...is it? Also, what is the point of passing in the last 'this' object? The logic contained in this.somePanel.someTabPanel.setAsUnSelected(); should be executed afterrender..so why are we passing the arg 'this' to the on function after the function is executed?


You should really look at the API documentation: http://dev.sencha.com/deploy/dev/docs/

If this event was for the EditorGridPanel ( http://dev.sencha.com/deploy/dev/docs/?class=Ext.grid.EditorGridPanel ), it shows that an Ext.Component is passed in. The variable name 'cmp' is just a name - it has no real meaning. In this case, it just refers to the component that is passed in (the editor grid in this case). For this same EditorGridPanel (or whatever component you're using), look at the method definition for 'on':

on( String eventName, Function handler, [Object scope], [Object options] ) : void

It takes an eventName: 'afterrender', a function handler: your "function(cmp) {...}, and the next parameter is the "scope" that the function is called in. In this case, the scope is "this". As with all javascript functions, you can leave later arguments off (you don't need to pass in "this" if you don't need it)

Maybe if I reformat your script it will be clearer:

this.on(
  'afterrender',  //this is the first parameter passed to the 'on' method
  function(cmp) {
    this.somePanel.someTabPanel.setAsUnSelected(); 
  },  //the function that will be called (after rendering) is the 2nd parameter
  this //this is 3rd argument that the "on" method takes, the "scope that the function is called in
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜