Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在extjs中将多余的参数传递给this.on函数?_Extjs - Fatal编程技术网

为什么在extjs中将多余的参数传递给this.on函数?

为什么在extjs中将多余的参数传递给this.on函数?,extjs,Extjs,在特定组件中,我看到的是现有代码: this.on('afterrender',function(cmp){ this.somePanel.someTabPanel.setAsUnSelected(); },this); 我的问题是:什么是cmp?这不是像btn或e这样的性病,是吗? 另外,传入最后一个“this”对象的意义是什么?this.somePanel.someTabPanel.setasonselect中包含的逻辑;应该在Render后执行。那么,为什么我们要在函数执行后将参数“t

在特定组件中,我看到的是现有代码:

this.on('afterrender',function(cmp){
this.somePanel.someTabPanel.setAsUnSelected(); 
},this);
我的问题是:什么是cmp?这不是像btn或e这样的性病,是吗?
另外,传入最后一个“this”对象的意义是什么?this.somePanel.someTabPanel.setasonselect中包含的逻辑;应该在Render后执行。那么,为什么我们要在函数执行后将参数“this”传递给on函数呢?

您真的应该看看API文档:

如果此事件是针对EditorGridPanel的,则表明传入了一个Ext.组件。变量名“cmp”只是一个名称,它没有实际意义。在本例中,它只引用在本例中编辑器网格中传递的组件。对于同一个EditorGridPanel或您正在使用的任何组件,请查看“on”的方法定义:

on( String eventName, Function handler, [Object scope], [Object options] ) : void
它接受一个eventName:'afterrender',一个函数处理程序:您的functioncmp{…},下一个参数是调用函数的范围。在这种情况下,范围是这样的。与所有javascript函数一样,您可以不使用后面的参数,如果不需要,您不需要传入这些参数

如果我重新格式化您的脚本,可能会更清晰:

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
);

你好。在确切指定传递给事件处理程序的参数的API文档旁边,请尝试处理程序中的console.dircmp。这会向您的开发控制台firebug或safari/chrome中的开发工具输出一个很好的可导航对象,在其中很容易看到它是什么动物