2010年3月1日月曜日

ExtJs-76 addListnerのスコープ

GridViewのハンドラをControlerとして外に出してディスパッチャとして実装したかったんだけど
どうもControlerでのthisがおかしい。スコープの指定が間違ってた。

またまちがえそうだから残しておこう。

GridViewのinitcomponent内で
//ExtJs提供イベント
this.addListener('rowdblclick', this._control.onRowDblClick, this._control, null) ;
this.addListener('rowcontextmenu', this._control.onRowContextMenu, this._control, null);

第三引数がthisだったから、onRowDblClick、onRowContextMenuでのthisがGridViewになってたわけで。。

コントローラはこんな感じにしておこう。
引数は後からconfigでまとめる。
ダイアログはどーしよ。。。
BaseIF.Control = function( dialog, model ){
var me = this;
me._dialog = dialog;
me._model = model;
//ダイアログの表示
me._dispDetailView = function(){
me._dialog.show();
};
};
BaseIF.Control.prototype = {
/**
* @onSave
*/
onSave: function(){
this._model.doSave();
},
//Loadイベントハンドラ
onLoad: function(){
this._model.doLoad();
},
//Addイベントハンドラ
onAddRec: function(){
this._model.doAddRec();
},
//Copyイベントハンドラ
onCopyRec: function(){
this._model.doCopyRec();
},
//Delイベントハンドラ
onDelRec: function(){
this._model.doDelRec();
},
//Detailダイアログ表示
onDispDetailView: function(){
this._dispDetailView();
},
//------------------------------
// ハンドラ/コールバック
//------------------------------
//ダブルクリック時イベントハンドラ
onRowDblClick : function(){
this._dispDetailView();
},
//コンテキストメニュー時イベントハンドラ
onRowContextMenu : function( grid, rowIndex, e )
{
menu = new Ext.menu.Menu(
[
{
text: '追加',
iconCls: 'icon-add',
handler: this.onAddRec,
scope: this
}, {
text: '複製',
iconCls: 'icon-copy',
handler: this.onCopyRec,
scope: this
}, {
text: '削除',
iconCls: 'icon-delete',
handler: this.onDelRec,
scope: this
}, {
text: '保存',
iconCls: 'icon-delete',
handler: this.onSave,
scope: this
}, {
text: '更新',
iconCls: 'icon-delete',
handler: this.onLoad,
scope: this
}, {
text: '編集',
iconCls: 'icon-delete',
handler: this.onDispDetailView,
scope: this
}
]);
//システムコンテキスト解除
e.stopEvent();
menu.showAt(e.getPoint());
}
};

なーんかうまくまとまらないなぁ。。。またつくりなおすかなぁ。だめだ。もうねよ。

0 件のコメント: