定义一个新的组件,override属性设为要重写的源组件javascript
例子:
Extjs4.2.3遇到的一个bug,Datefield 选择不了年月,会自动关闭
sencha论坛具体的讨论php
重写组件的代码以下,该组件的方法会覆盖掉原来的方法,
再将该组件放进overrides文件夹
(不一样版本可能有所不同)
或者
将该组件放进项目代码下,而且在viewport初始化时引入
html
/** * This override fixes an ExtJS 4.2.3 defect where the picker closes early. * * @markdown * @docauthor Rex Staples */ Ext.define('app.view.FormFieldDate', { override: 'Ext.form.field.Date', // Overrides code below come from ExtJS 4.2.2 // http://docs.sencha.com/extjs/4.2.2/source/Picker.html#Ext-form-field-Picker /** * @private * Runs on mousewheel and mousedown of doc to check to see if we should collapse the picker */ collapseIf: function(e) { var me = this; if (!me.isDestroyed && !e.within(me.bodyEl, false, true) && !e.within(me.picker.el, false, true) && !me.isEventWithinPickerLoadMask(e)) { me.collapse(); } }, mimicBlur: function(e) { var me = this, picker = me.picker; // ignore mousedown events within the picker element if (!picker || !e.within(picker.el, false, true) && !me.isEventWithinPickerLoadMask(e)) { me.callParent(arguments); } }, /** * returns true if the picker has a load mask and the passed event is within the load mask * @private * @param {Ext.EventObject} e * @return {Boolean} */ isEventWithinPickerLoadMask: function(e) { var loadMask = this.picker.loadMask; return loadMask ? e.within(loadMask.maskEl, false, true) || e.within(loadMask.el, false, true) : false; } });
在初始化时调用Ext.override()方法并重写须要的方法java
Ext.override(Ext.menu.DatePicker, { owns: function(element) { if (this.picker && this.picker.monthPicker && this.picker.monthPicker.owns(element)) { return true; } return this.callParent(arguments); } });