定義一個新的組件,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); } });