ExtJS 没有使用我的网格过滤器覆盖
ExtJS is not using my grid filter override
我有一个项目需要制作自定义网格日期过滤器。
在状态保存之前一切正常。我需要向状态添加自定义值。我覆盖了扩展 Ext.util.Filter
的 class 中的 getState
方法:
Ext.define('RelativeDateUtilFilter', {
extend: 'Ext.util.Filter',
getState: function () {
var config = this.getInitialConfig(),
result = {},
name;
for (name in config) {
if (config.hasOwnProperty(name)) {
result[name] = config[name];
}
}
delete result.root;
result.value = this.getValue();
//this is the line I added
result.relValue = this.relValue;
this.callParent();
return result;
}
});
我重写了过滤器基础 class 以使其使用我自己的实用程序过滤器 :
createFilter: function (config, key) {
var filter = new RelativeDateUtilFilter(this.getFilterConfig(config, key));
filter.isGridFilter = true;
return filter;
}
问题是,我在 RelativeDateUtilFilter
class 中的 getState
仅在我第一次创建过滤器时被调用。当 ExtJS 保存状态时,它使用基础 class Ext.util.Filter
.
中的状态
我可以通过将我的代码直接放在 Ext.util.Filter
class 中来解决一些问题,但我不想这样做,因为如果我想升级,它就不好。
简而言之,如何在写状态时强制ExtJS使用我自己的getState
方法?
感谢任何帮助!
编辑:
如果这对某人有帮助,我通过删除我的 RelativeDateUtilFilter
class 和我的过滤器基础覆盖并将我的 getState
方法放在覆盖文件中来解决这个问题:
Ext.define('Override.util.Filter', {
override :'Ext.util.Filter',
getState: function () {
var config = this.getInitialConfig(),
result = {},
name;
for (name in config) {
// We only want the instance properties in this case, not inherited ones,
// so we need hasOwnProperty to filter out our class values.
if (config.hasOwnProperty(name)) {
result[name] = config[name];
}
}
delete result.root;
result.value = this.getValue();
if(this.relValue) {
result.relValue = this.relValue;
}
return result;
}
});
(在 /overrides/util/Filter,js 文件中,因此它被 SenchaCMD 正确加载)
再次感谢@bullettrain!
我相信你不需要 this.callParent();在你重写的方法中,这里有一个关于重写方法的不同方法的很好的解释 https://sencha.guru/2015/01/20/overriding-methods-safely/
我有一个项目需要制作自定义网格日期过滤器。
在状态保存之前一切正常。我需要向状态添加自定义值。我覆盖了扩展 Ext.util.Filter
的 class 中的 getState
方法:
Ext.define('RelativeDateUtilFilter', {
extend: 'Ext.util.Filter',
getState: function () {
var config = this.getInitialConfig(),
result = {},
name;
for (name in config) {
if (config.hasOwnProperty(name)) {
result[name] = config[name];
}
}
delete result.root;
result.value = this.getValue();
//this is the line I added
result.relValue = this.relValue;
this.callParent();
return result;
}
});
我重写了过滤器基础 class 以使其使用我自己的实用程序过滤器 :
createFilter: function (config, key) {
var filter = new RelativeDateUtilFilter(this.getFilterConfig(config, key));
filter.isGridFilter = true;
return filter;
}
问题是,我在 RelativeDateUtilFilter
class 中的 getState
仅在我第一次创建过滤器时被调用。当 ExtJS 保存状态时,它使用基础 class Ext.util.Filter
.
中的状态
我可以通过将我的代码直接放在 Ext.util.Filter
class 中来解决一些问题,但我不想这样做,因为如果我想升级,它就不好。
简而言之,如何在写状态时强制ExtJS使用我自己的getState
方法?
感谢任何帮助!
编辑:
如果这对某人有帮助,我通过删除我的 RelativeDateUtilFilter
class 和我的过滤器基础覆盖并将我的 getState
方法放在覆盖文件中来解决这个问题:
Ext.define('Override.util.Filter', {
override :'Ext.util.Filter',
getState: function () {
var config = this.getInitialConfig(),
result = {},
name;
for (name in config) {
// We only want the instance properties in this case, not inherited ones,
// so we need hasOwnProperty to filter out our class values.
if (config.hasOwnProperty(name)) {
result[name] = config[name];
}
}
delete result.root;
result.value = this.getValue();
if(this.relValue) {
result.relValue = this.relValue;
}
return result;
}
});
(在 /overrides/util/Filter,js 文件中,因此它被 SenchaCMD 正确加载)
再次感谢@bullettrain!
我相信你不需要 this.callParent();在你重写的方法中,这里有一个关于重写方法的不同方法的很好的解释 https://sencha.guru/2015/01/20/overriding-methods-safely/