ExtJS 4及其新的MVC:grid:如何处理密钥?

Oli*_*ons 3 javascript grid extjs extjs4

我正在寻找一种方法来处理Grid中的键.我密切关注这里的例子: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/

所以现在一切正常,但我想在网格中处理键.

所以我想在声明" this.control({})"我应该添加另一个事件,userlist但似乎Grid没有"keypress"事件.

知道我应该怎么做(而且我应该如何处理新的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();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

Amo*_*are 6

创建视图后,在右侧定义KeyMaplaunch: function() {...}.

  • 当你这么说时,你很善良.我认为(但不要说)更顽皮的事情.没有答案.决不.或完全没用.我几乎后悔花了这么多时间在一个很少帮助的框架上.所以经过4天的提问,如果我没有在他们的论坛中回答(8次中有7次这样的情况)我觉得随风飘扬,所以我在这里发布.再次感谢. (2认同)