Best practice for overriding classes / properties in ExtJS?

后端 未结 2 476
野的像风
野的像风 2020-11-27 13:11

I have an Ext.form.field.Text and I want to override the setValue function.

What is the recommended way to override this class functionalit

2条回答
  •  难免孤独
    2020-11-27 13:51

    The answer by @sra is great and was very helpful to me in gaining a deeper understanding of the override functionality available in Ext, but it does not include the way that I most commonly implement overrides which looks something like this:

    Ext.define('my.application.form.field.Text' {
        override: 'Ext.form.field.Text'
        getValue: function () {
            // your custom functionality here
            arguments[1] = false;
    
            // callParent can be used if desired, or the method can be 
            // re-written without reference to the original
            this.callParent(arguments)
        }
    });
    

    I'm still using Ext 5 so I would then load this file in my Application.js and add it to the requires array there which applies the override to the app globally. I think Ext 6 projects include an override folder and simply adding this file to that folder ensures the override is applied.

提交回复
热议问题