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
从ExtJS4组合框侦听器调用函数_Extjs_Extjs4_Extjs Mvc - Fatal编程技术网

从ExtJS4组合框侦听器调用函数

从ExtJS4组合框侦听器调用函数,extjs,extjs4,extjs-mvc,Extjs,Extjs4,Extjs Mvc,我在ExtJS4中从组合框侦听器调用自定义函数时遇到问题。 我已经设置了组合框侦听器,如下所示 listeners:{ select:{ fn:function(combo, value) { this.test; } } } 我的自定义函数是在关闭 this.callParent(arguments); 我的自定义函数是 test: function(){ alert('test'); }

我在ExtJS4中从组合框侦听器调用自定义函数时遇到问题。 我已经设置了组合框侦听器,如下所示

listeners:{
    select:{
        fn:function(combo, value) {
            this.test;
        }
    }
}
我的自定义函数是在关闭

 this.callParent(arguments);
我的自定义函数是

  test: function(){
        alert('test');
  }

我做错了什么?

您的作用域错误,选择函数中的
指向您的组合,而您的测试函数所在的对象可能没有。此外,如果调用一个函数,则需要在其周围使用大括号:
this.test()

或许最好采用以下方式:

initComponent: function() {  
    var me = this;
    me.items = [//... 
    {
       xtype: 'boxselect',
       //props...
       listeners: {
           select:{
               fn:function(combo, value) {
                   this.test(); // this will now be the this variable that you give to your scope.
                   //Or simply: me.test();
               }
           },
           scope: me
       }
    }
    //...
    ];

    me.callParent();
}
您可能想发布更多的代码,因为我们需要知道测试函数的范围和组合框的范围。

下面是我的代码

  initComponent: function() {           
            this.items = [
            {
                    xtype: 'form',
                    padding: '5 5 0 5',
                    autoScroll:true,
                    border: false,
                    style: 'background-color: #fff;',
                      items: [
                      {
                            xtype:'fieldset',

                        columnWidth: 0.5,
                        id:'adfieldset',
                        title: 'Ad Details',
                        collapsible: true,
                        defaultType: 'textfield',
                        defaults: {anchor: '100%'},
                        layout: 'anchor',

                          items: [
                          {
                                    xtype : 'boxselect',
                                    store : 'product.CategoryComboBox',
                                    name: 'category[]',
                                    id:'category',
                                    displayField: 'name',
                                    valueField: 'idProductCategory',
                                    multiSelect : false,
                                    fieldLabel: 'Category',
                                    //allowBlank: false,
                                    allowQueryAll : false,
                                    multiSelect : true,
                                    forceSelection : true,
                                    typeAhead: true,
                                    triggerAction: 'all',
                                    delimiter : ',',
                                    width: 300,
                                    queryMode:'local',


                                    listeners:{select:{fn:function(combo, value) {
                                       this.test;

代码不完整,但我非常确定这是一个范围问题,正如我下面的回答。那么有没有办法解决范围问题。请让我知道。我发布了一个解决方案,应该可以,你至少试过了吗?