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
Javascript Extjs侦听器不在配置中_Javascript_Function_Extjs_Listener - Fatal编程技术网

Javascript Extjs侦听器不在配置中

Javascript Extjs侦听器不在配置中,javascript,function,extjs,listener,Javascript,Function,Extjs,Listener,嗨,extjs专家们,我有一个简单的问题,但找不到正确的方法,我在谷歌上搜索了几天。我在extjs元素的配置中有一个监听器,这样做很容易,但是我如何将监听器从配置中取出,并将其放在配置之外,这样配置将尽可能少,并且一个监听器可以多次使用,只要函数调用正确, 这是我的密码: Ext.define("my.filter.TimeFilter",{ extend: "Ext.tab.Panel", alias: "widget.myTimeFilter", requires: ["my.filter.

嗨,extjs专家们,我有一个简单的问题,但找不到正确的方法,我在谷歌上搜索了几天。我在extjs元素的配置中有一个监听器,这样做很容易,但是我如何将监听器从配置中取出,并将其放在配置之外,这样配置将尽可能少,并且一个监听器可以多次使用,只要函数调用正确, 这是我的密码:

Ext.define("my.filter.TimeFilter",{
extend: "Ext.tab.Panel",
alias: "widget.myTimeFilter",
requires: ["my.filter.Filters"],
config: {
    cls: 'ruban-filter-timefilter',
     items: [
            {
                title: 'Time sections',
                xtype: 'radiogroup',
                fieldLabel: 'Time Selector',
                items: [
                    {
                        boxLabel: '60 Mins',
                        name: 'unixMills',
                        inputValue: '3600000'
                    }, {
                        boxLabel: '8 Hours',
                        name: 'unixMills',
                        inputValue: '28800000'
                    }, {
                        boxLabel: '24 Hours',
                        name: 'unixMills',
                        inputValue: '86400000'
                    }, {
                        boxLabel: '7 Days',
                        name: 'unixMills',
                        inputValue: '604800000'
                    }, {
                        boxLabel: '30 Days',
                        name: 'unixMills',
                        inputValue: '2592000000'
                    }
                    ],
                    listeners: {
                        change: function (field, newValue, oldValue) {
                            var endTime = new Date().getTime();
                            var startTime = endTime - newValue['unixMills'];
                            console.log("StartTime: " + startTime);
                            console.log("EndTime: " + endTime);

                        }


            }
        ]
    },

constructor: function(config){
    this.callParent(arguments);
}
}))

所以我认为它应该作为单独的函数或监听器本身去寻找构造函数,但我不知道,对js和extjs不太熟悉,
谢谢大家

您可以通过以下方式在配置之外添加侦听器:

myElement.on('change', function () { ... }

有相当多的可能性

如果你有很多基于事件的逻辑,你总是可以创建一个控制器,让他们监听组件。这里的控制器文档应该能让您很好地了解如何将其结合在一起: