Ext修复源代码出现的问题
1.使用override属性,重写组件
定义一个新的组件,override属性设为要重写的源组件
例子:
Extjs4.2.3遇到的一个bug,Datefield 选择不了年月,会自动关闭
sencha论坛具体的讨论
重写组件的代码如下,该组件的方法会覆盖掉原来的方法,
再将该组件放进overrides文件夹
(不同版本可能有所不一样)
或者将该组件放进项目代码下,并且在viewport初始化时引入
/**
* 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;
}
});
2.使用Ext.override()方法重写组件
在初始化时调用Ext.override()方法并重写需要的方法
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);
}
});