当一个页面有多个结构相同的Ext.grid.EditorGridPanel时,我们可能定义一个列信息,
var columns = [{},{},{}...]; // 1、这里指定不指定editor,
然后多次使用这个数组初始化各个Grid的ColumnModel:
var cm = new new Ext.grid.ColumnModel(columns);
//2、 或是这里再指定editor,现象都一样。
?
然后就会出现某个Grid的某个列第一次编辑以后,其他Grid的此列都不能编辑了。
说明columns数组或是其中的各个对象被共享了。
翻开3.0源码一看,果然,直接在setConfig方法中this.config = config了,(ps:发现创建editor的代码在source中的和ext-all-debug.js中的代码是不一致的。)。
?
将这个几句代码稍微改改,不直接用config就可以实现共用了。
Ext.grid.ColumnModel.prototype.setConfig =function(config, initial){
if(!initial){ delete this.totalWidth;
for(var i = 0, len = this.config.length; i < len; i++){
var c = this.config[i];
if(c.editor){
c.editor.destroy();
}
}
}
this.config = [];
this.lookup = {};
for(var i = 0, len = config.length; i < len; i++){
var col = Ext.apply({},config[i]);
this.config.push(col);
var c = Ext.applyIf(col, this.defaults);
if(typeof c.renderer == "string"){
c.renderer = Ext.util.Format[c.renderer];
}
if(typeof c.id == "undefined"){
c.id = i;
}
if(c.editor && c.editor.isFormField){
c.editor = new Ext.grid.GridEditor(c.editor);
}
this.lookup[c.id] = c;
}
if(!initial){
this.fireEvent('configchange', this);
}
}
?
?
?
1 楼
yiminghe
2009-12-17
我觉得其实 extjs 觉得一个 config 一般是一个组件用(效率考虑,没有深拷贝),没想到你这样一个config多个组件公用,这样的话应该你负责
Object.clone=function(deep){...}
new xx(config.clone(true));
这只是我的想法,你这样子改ext源码麻烦了点,呵呵
Object.clone=function(deep){...}
new xx(config.clone(true));
这只是我的想法,你这样子改ext源码麻烦了点,呵呵
2 楼
yiminghe
2009-12-17
是
Object.prototype.clone=function(deep){
//xxxx
}
今年某个公司的笔试题,:)
Object.prototype.clone=function(deep){
//xxxx
}
今年某个公司的笔试题,:)
3 楼
kimmking
2009-12-17
yiminghe 写道
我觉得其实 extjs 觉得一个 config 一般是一个组件用(效率考虑,没有深拷贝),没想到你这样一个config多个组件公用,这样的话应该你负责
Object.clone=function(deep){...}
new xx(config.clone(true));
这只是我的想法,你这样子改ext源码麻烦了点,呵呵
Object.clone=function(deep){...}
new xx(config.clone(true));
这只是我的想法,你这样子改ext源码麻烦了点,呵呵
和几个人讨论过clone,extjs就是缺少一个json的深度clone方法。
自己实现也不难。