Ext.draw.Component を拡張する Sencha クラスがあり、MyModel のストアを受け入れます。2 つの異なる方法を試していますが、異なる満足のいく結果が得られません。
クラスのコンストラクター内の最初のメソッド
ストアで読み取り、次のことを行います。
//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 内) に配置すると、例外が発生します。
キャッチされていない TypeError: 未定義のメソッド 'apply' を呼び出せません
2 番目の方法
ただし、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 を作成する別の方法はありますか? 私は何が欠けていますか?2 番目の方法は正しくないようですが、最初の方法では例外を取り除くことができません。