2012-01-17 44 views
0

我已經添加了一個工具欄到我的網格 我無法綁定控制器/控制中的事件 當代碼解釋它本身時,它是無聊的:)Extjs將事件添加到網格形式的按鈕控制器

Ext.define('SA.view.user.List' ,{ 
    extend: 'Ext.grid.Panel', 
    alias : 'widget.userlist', 
    title : 'All Users', 
    store: 'Users', 
    initComponent: function() { 

    this.columns = [ 
     { 
     header: 'Id', 
     sortable: true, 
     dataIndex: 'id', 
     flex: 1, 
     field: { 
     type: 'textfield' 
     } 
    }, 
    { 
     header: 'Name', 
     sortable: true, 
     dataIndex: 'uname', 
     flex: 1, 
     field: { 
     type: 'textfield' 
     } 
    }, 
    { 
     header: 'Email', 
     sortable: true, 
     dataIndex: 'email', 
     flex: 1, 
     field: { 
     type: 'textfield' 
     } 
    } 
    ]; 

    this.callParent(arguments); 
    }, 

    dockedItems: [ 
    { 
    xtype: 'toolbar', 
    items: [{ 
     iconCls: 'icon-add', 
     text: 'Add', 
     scope: this 

    }, { 
     iconCls: 'icon-delete', 
     text: 'Delete', 
     disabled: true, 
     itemId: 'delete', 
     scope: this 

    }] 
    }, 
    { 
    xtype: 'pagingtoolbar', 
    store: 'Users', // same store GridPanel is using 
    dock: 'bottom', 
    displayInfo: true 
    } 
    ] 
}); 

如何能在控制器內處理程序中的單擊事件形式

init: function() { 
    this.control({ 
     'userlist': { 
      itemdblclick: this.editUser 
     }, 
     'userlist > toolbar/*my attempt but it doesnt work :(*/': { 
      click: this.insertUser 
     }, 
     'useredit button[action=save]': { 
      click: this.updateUser 
     } 
    }); 
}, 

再見

+0

我做了一招:)的xtype: '工具欄', 項目:[{ iconCls: '圖標添加', ID: 'B-ADD', 文字: '添加', 範圍: }'userlist> toolbar> button#b-add' – Whisher 2012-01-17 10:49:31

+0

這不是一個好主意。使用嚴格的ID是不好的做法。 – erlrange 2012-01-17 14:15:01

回答

3

也許你可以瓚GE像這樣

dockedItems: [ 
    { 
    xtype: 'toolbar', 
    items: [{ 
     iconCls: 'icon-add', 
     text: 'Add', 
     action: 'add', 
     scope: this 

    }, { 
     iconCls: 'icon-delete', 
     text: 'Delete', 
     action: 'delete', 
     disabled: true, 
     itemId: 'delete', 
     scope: this 

    }] 
    }, 


init: function() { 
    this.control({ 
     'userlist': { 
      itemdblclick: this.editUser 
     }, 
     'userlist button[action=add]': { 
      click: this.insertUser 
     }, 
     'useredit button[action=save]': { 
      click: this.updateUser 
     } 
    }); 
}, 
1

嘗試userlist button[text=Delete]': { click: this.insertUser }userlist button[itemId=delete]': { click: this.insertUser }

這個選擇器類似於CSS的選擇器,所以通常你會使用container > child_subcontainer another_subcontainer element[property=value]。在控制器下面使用Ext.ComponentQuery,所以你可能想玩它來檢查它可以。

0

只需添加行動部分也將工作。

init: function() { 
    this.control({ 
     'userlist': { 
      itemdblclick: this.editUser 
     }, 
     'userlist > toolbar > button[action=add]': { 
      click: this.insertUser 
     }, 
     'useredit button[action=save]': { 
      click: this.updateUser 
     } 
    }); 
},