2011-08-04 50 views
3

我正在尋找一種方法來處理網格中的密鑰。 我密切關注這裏的例子: http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-1 http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-2
http://www.sencha.com/learn/the-mvc-application-architecture/ExtJS 4及其新的MVC:grid:如何處理密鑰?

所以現在一切工作正常,但我想,以處理我的網格鍵。

所以我想在聲明「this.control({})」我應該只是添加有關userlist的另一個事件,但它似乎網格沒有「按鍵」事件。

任何想法我應該怎麼做(此外,我應該如何處理新的MVC模式)?

Ext.define('GS.controller.Users', { 

    extend: 'Ext.app.Controller', 

    models: [ 
     'User' 
    ], 

    stores: [ 
     'Users' 
    ], 

    views: [ 
     'user.List', 
     'user.Edit' 
    ], 

    init: function() { 
     this.control({ 
      /* (!) Actions in 'userlist' */ 
      'userlist': { 
       selectionchange: this.userListSelectionChange, 
       itemdblclick: this.userEdit 
      }, 
      'userlist button[action=create]': { 
       click: this.userCreate 
      }, 
      'userlist button[action=delete]': { 
       click: this.userDelete 
      }, 
      /* (!) Actions in 'useredit' */ 
      'useredit button[action=create]': { 
       click: this.userCreateValidate 
      }, 
      'useredit button[action=save]': { 
       click: this.userEditValidate 
      } 
     }); 
    }, 

    userListSelectionChange: function(grid, selections, options) { 
     var panel = grid.view.up('panel'), 
      button = panel.down('button[action=delete]'); 

     button.setDisabled(selections.length === 0); 
    }, 

    userCreate: function(button) { 
     /* Using Ext.create() to pass variable create:true 
     * instead of the shortcut: 
     * var view = Ext.widget('useredit'); 
     */ 
     var view = Ext.create('GS.view.user.Edit', { 
      create:true 
     }); 
    }, 

    userCreateValidate: function(button) { 
     var win = button.up('window'), 
      form = win.down('form'), 
      values = form.getValues(); 

     this.getUsersStore().add(values); 
     this.getUsersStore().sync(); 
     win.close(); 
    }, 

    userEdit: function(grid, record) { 
     var view = Ext.widget('useredit'); 
     view.down('form').loadRecord(record); 
    }, 
    userEditValidate: function (button) { 
     var win = button.up('window'), 
      form = win.down('form'), 
      record = form.getRecord(), 
      values = form.getValues(); 

     record.set(values); 
     win.close(); 
     this.getUsersStore().sync(); 
    }, 

    userDelete: function(button) { 
     var panel  = button.up('panel'), 
      selection = panel.getSelectionModel().getSelection()[0]; 

     if (selection) { 
      var store = this.getUsersStore(); 
      store.remove(selection); 
      store.sync(); 
     } 
    } 
}); 

回答

6

定義KeyMap(s)launch: function() {...}在創建視圖之後。

+1

非常感謝。可惜的是我在stackoverflow上比在Sencha網站上得到的答案更快! –

+2

當你這麼說的時候,你很善良。我認爲(但不要說)事情更頑皮。沒有答案。決不。或者完全沒用。我幾乎很遺憾,花了那麼多時間在一個只有很少幫助的框架上。因此,在問了4天的問題後,如果我在論壇中沒有回答(8次中有7次是這種情況),我覺得自己喜歡隨風吐痰,所以我把它放在這裏。再次感謝。 –

+0

@oliver歡迎來到Sencha – cbmeeks