4

保存ボタンを押すと、正常に動作します。しかし、このフィールドでEnterキーを押すと、エラーメッセージが this.up(...).down(...) is null であるという問題に直面します。ウィンドウからの私のものを以下に示します。テキストボックスで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()フィールドの直接の親 (フォーム パネル) を対象とする 1 つのレベルのみをバブル アップします。代わりに次のオプションのいずれかを試してください。

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 に答える