ExtJS 4 及其新的 MVC:网格:如何处理键? [英] ExtJS 4 and its new MVC: grid: how to handle keys?

查看:21
本文介绍了ExtJS 4 及其新的 MVC:网格:如何处理键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来处理网格中的键.我密切关注这里的例子:http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-1http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-2
http://www.sencha.com/learn/the-mvc-application-架构/

I'm looking for a way to handle the key in the Grid. I've closely followed the examples here: 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/

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

So now everything works fine, but I'd like to handle keys in my Grid.

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

So I guess in the declaration "this.control({})" I should just add another event concerning userlist but it seems Grid don't have the "keypress" event.

知道我应该怎么做(此外我应该如何使用新的 MVC 模式)?

Any idea how I should do (moreover how I should do with the new MVC pattern)?

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();
        }
    }
});

推荐答案

Define KeyMap(s) 在您创建视图后立即在 launch: function() {...} 中.

Define KeyMap(s) in your launch: function() {...} right after you create the view.

这篇关于ExtJS 4 及其新的 MVC:网格:如何处理键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆