4

当我按下保存按钮时,它工作正常。但是当我在此字段上按 Enter 时遇到一些问题,错误消息是 this.up(...).down(...) 为空。下面给出了我的来自窗口。我只是想,当您在文本框上按 Enter 时,它会像您单击按钮一样。

任何人都可以帮忙吗?

Ext.define('${pkgName}.v01i002001.SV01I00200201' , {
    extend      : 'Ext.window.Window',
    alias       : 'widget.sv01i00200201',
    id          : 'sv01i00200201',   
    title       : 'MANUFACTURE :: SV01I00200201',
    minimizable : false,
    maximizable : false,
    autoShow    : true,
    resizable   : false,
    border      : false,
    modal       : true,
    padding     : '0 5 0 5',
    icon        : "${resource(dir: 'images', file: 'APP01003.png')}",
    layout    : {
        type: 'vbox',
        align: 'stretch'
    },
    initComponent : function () {
        var me = this; 
        var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';       
        this.items = [
        {
            xtype     : 'form',
            bodyStyle : {
                padding   : '10px',
                border    : true
            },
            tbar: Ext.create('Ext.ux.StatusBar', {
                id              : 'win-statusbar-sv01i00200201',
                topBorder       :true,
                text            :'Status',
                defaultIconCls  : 'info',
                defaultText     : 'Status'
            }),
            items : [{
                xtype             : 'textfield',
                fieldLabel        : 'Id',
                name              : 'id',
                width             : 265,
                anchor            : '95%',
                emptyText         : 'Not need...',
                readOnly          : true
            },{
                xtype             : 'textfield',
                fieldLabel        : 'Manufac. Name',
                emptyText         : 'Write Manufacturer name',
                allowBlank        :  false,
                name              : 'name',
                width             :  265,
                anchor            : '95%',
                listeners: {
                    specialkey    : function(field, e){
                        if (e.getKey() == e.ENTER || e.getKey()==e.TAB) {                                    
                            //Ext.get('save-sv01i00200201').dom.click();                              //it work
                           // this.up().up().down('button[action=save]').fireEvent('click');          //TypeError: button.up is not a function
                           // this.up('sv01i00200201').down('button[action=save]').fireEvent('click');//TypeError: button.up is not a function
                           // this.up('window').down('button[action=save]').fireEvent('click');       //TypeError: button.up is not a function
                        }
                    }
                }
            }]
        }]
        this.buttons = [
        {
            text    : 'Save',
            icon    : "${resource(dir: 'images', file: 'SAV01004.png')}",
            id      : 'save-sv01i00200201',
            action  : 'save'
        },{
            text    : 'Close',
            icon    : "${resource(dir: 'images', file: 'CLS01001.png')}",      
            scope   : this,
            handler : function(button){
                var win = button.up('window');
                win.close();
            }
        }]
        me.callParent(arguments);
    }
});

我的控制器在下面给出

Ext.define('${pkgName}.C01I002001', {
    extend  : 'Ext.app.Controller', 
    requires: [],

    views:[
        'V01I001000',
        'v01i002001.SV01I00200100',
        'v01i002001.SV01I00200101',
        'v01i001001.SV01I00200104',
        'v01i001001.SV01I00200106',
        'v01i002001.SV01I00200201',
        'v01i002001.SV01I00200301'
    ],
    refs    : [{
            ref : 'v01i002001',
            selector: 'window'
        }],
    init: function() {
        manuStore   = Ext.data.StoreManager.get('S01I002001'); 
        var me      = this;
        me.category = undefined;        
        me.control({             
            'sv01i00200201 button[action=save]': {
                click           :   this.manufacturerSave
            }
        });
    },
    manufacturerSave   :   function(button){
        win     = button.up('window'),
        form    = win.down('form'),
        record  = form.getRecord(),
        values  = form.getValues();

        if(form.getForm().isValid()){

            var manufacturer    = Ext.create('${appName}.model.M01I002001',{
                name:values.name
            });        

            manufacturer.save({
                scope:this,
                success:function(records, operation){
                    var text     = operation.response.responseText,
                    json         = Ext.decode(text);
                    form.loadRecord(records);
                    controller000.statusbar('sv01i00200201', json.message, 'saveInfo', 'activecaption');
                    manuStore.load();
                    var win       = Ext.getCmp('sv01i00200201');
                    controller000.closeWindow(win);
                },

                failure:function(model, operation){
                    controller000.statusbar('sv01i00200201', operation.error, 'warnInfo', 'red');
                } 
            }); 
        }else{
            controller000.statusbar('sv01i00200201', 'Necessary Field Required', 'warnInfo', 'red');

        }
    }
});
4

2 回答 2

5

this.up()仅针对您的字段的直接父级(表单面板)通过一个级别冒泡。请尝试以下选项之一:

this.up().up().down('button[action=save]').fireEvent('click');
this.up('window').down('button[action=save]').fireEvent('click');
this.up('#sv01i00200201').down('button[action=save]').fireEvent('click');

看看文档;)


第 2 部分:“button.up 不是函数”

我想我明白了,您必须手动将按钮作为参数传递给fireEvent函数:

var button = this.up('window').down('button[action=save]');
button.fireEvent('click', button);
于 2013-03-16T10:01:25.710 回答
1

最后我通过创建 id 来做到这一点

 Ext.get('save-sv01i00200201').dom.click();

按钮修改并创建 id

{
        text    : 'Save',
        icon    : "${resource(dir: 'images', file: 'SAV01004.png')}",
        id      : 'save-sv01i00200201',
        action  : 'save'
    }
于 2013-03-16T08:53:19.783 回答