【问题标题】:extjs combo override : why define this.addevents()?extjs 组合覆盖:为什么要定义 this.addevents()?
【发布时间】:2011-02-04 20:54:53
【问题描述】:

在应用程序中现有的 ext js 代码中,一个组合框被这样覆盖:

Ext.override(Ext.form.ComboBox, {
    nullable:true
    ,initComponent: Ext.form.ComboBox.prototype.initComponent.createSequence(function(){
        this.triggerConfig = {
            tag:'span', cls:'x-form-twin-triggers', cn:[
                {tag: "img", src: Ext.BLANK_IMAGE_URL, cls:'x-form-trigger '},
                {tag: "img", src: Ext.BLANK_IMAGE_URL, cls:'x-form-trigger x-form-clear-trigger'}
        ]};
        this.addEvents(
            'clear',
            'change'
        );

}})

为什么要定义:

this.addEvents(
                'clear',
                'change'
            );

'change' 已经被定义为 extjs 中组合框的事件。 'clear' 没有在 extjs 中定义。

编辑:也许对实际示例的引用会有所帮助:就是这样。 http://www.sencha.com/forum/showthread.php?84300-Nullable-ComboBox&p=404222&langid=14

【问题讨论】:

  • 确实如此。定义change 有点奇怪,因为无论如何它都是由feom Ext.form.Field 继承的。至于clear,也许它正在其他地方使用。 JavaScript 为您提供了传播定义的令人讨厌的可能性,因此它可能并不明显。

标签: extjs


【解决方案1】:

你会看到那里定义了这个方法:

clearValue:Ext.form.ComboBox.prototype.clearValue.createSequence(function(){
        if(this.trigger_clear){
            this.trigger_clear.hide();
        }
        this.fireEvent('clear',  this);
        this.fireEvent('change', this);
    })

因此调用这两个事件时只传递了一个参数(即组合框本身)。我认为没有必要在这里定义change 事件,因为它继承自Ext.form.Field。继承的change 事件的签名也是(field, newValue, oldValue),而这里只传递了一个参数。因此,我认为应该为这个活动使用另一个名字。

【讨论】:

    猜你喜欢
    • 2020-11-14
    • 2010-09-23
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    相关资源
    最近更新 更多