Ext.create("....")を使用するときに、初期化を行いたい。オブジェクトは単純で小さく、定義したくありませんが、(コンポーネント create が呼び出される前に) mixin からのメソッドが必要です...どうすればよいですか?
1677 次
2 に答える
2
標準インスタンスのオーバーライド
通常、
Ext.override()
afterを使用しExt.create()
て、クラスの特定のインスタンスにオーバーライドを適用します ( docsを参照)。var myObj = Ext.create('Ext.some.Component', { ... }); Ext.override(myObj, { myMethod: function() { // Do something. this.callParent(arguments); // From Ext.some.Component class. // Do something else. } });
this.callParent(arguments)
作成されたオーバーライドに対してのみ適切に機能しますExt.override()
、またはを介して明示的に- 暗黙的に
Ext.define()
特殊なケース: オーバーライドinitComponent
initComponent
メソッドはの実行中に呼び出されるため、Ext.create()
内でオーバーライドする必要がありますExt.create
。元のメソッドにアクセスするには、回避策を使用してオーバーライドされたメソッドにアクセスする必要があります。var myObj = Ext.create('Ext.some.Component', { initComponent: function() { // Do something. // Get a reference to the class. var myClass = Ext.getClass(this); // Apply the overridden method from the class' prototype. myClass.prototype.initComponent.apply(this, arguments); // Do something else. } });
于 2012-07-17T22:45:09.553 に答える
2
次の行に沿って何かをやっているようです:
Ext.create('Ext.panel.Panel', {
prop1: value1,
prop2: value2
});
その場合は、必要なことを行う関数である initComponent というプロパティを追加できるはずです。すべてが正しくビルドされるように、元の initComponent を呼び出すことを忘れないでください。
Ext.create('Ext.panel.Panel', {
prop1: value1,
prop2: value2,
initComponent: function () {
this.doSomething();
Ext.panel.Panel.prototype.initComponent.apply(this, arguments);
}
});
于 2012-07-17T18:21:06.167 に答える