我有一个扩展 Ext.draw.Component 的 Sencha 类,它接受 MyModel 的存储。我正在尝试两种不同的方法,但我得到了不同的、不令人满意的结果。
我在商店中读取的类的构造函数中的第一个方法并执行以下操作:
//Inside constructor of the class
this.store = config.store; //config is passed in from the constructor
var me = this;
me.store.each(function (model) {
me.renderTo = model.get('elementToRenderTo');
me.items = [{
type: 'rect',
x: 1.6620979,
y: 52.362183,
radius: 90,
width: 448.10959,
height: 1000,
fill: model.get('color'),
stroke: 'none'
}];
if (me.items) {
Ext.apply(config, { //config is passed in from the constructor
items: me.items
});
}
me.callParent([config]);
}
当我将最后一段代码放在它所在的位置(store.each 内部)时,我得到一个异常:
未捕获的类型错误:无法调用未定义的方法“应用”
第二种方法
但是,如果我将 Ext.apply 和 callParent 移到 store.each 之外,我不会有任何期望,但只会绘制最后一个模型(可能是因为 me.items 在每次迭代时都会被覆盖该模型)。
//Inside constructor of the class
this.store = config.store; //config is passed in from the constructor
var me = this;
me.store.each(function (model) {
me.renderTo = model.get('elementToRenderTo');
me.items = [{
type: 'rect',
x: 1.6620979,
y: 52.362183,
radius: 90,
width: 448.10959,
height: 1000,
fill: 'black',
stroke: 'none'
}];
}
if (me.items) {
Ext.apply(config, { //config is passed in from the constructor
items: me.items
});
}
me.callParent([config]);
还有另一种方法来创建使用商店的自定义 Ext.draw.Component 吗?我错过了什么?第二种方法似乎不对,但我无法摆脱第一种的异常。