简体   繁体   English

ExtJs按钮'click'监听器转到class方法

[英]ExtJs Button 'click' listener to go to class method

Given this class code: 鉴于此类代码:

///
/// FORM tBasicFrm
///
Ext.define('tBasicBrwFrm',{ extend: 'Ext.panel.Panel'
    ,id: 'tBasicBrwFrm'
    ,layout: 'fit'

    ///
    /// CUSTOM PROPERTIES
    ///
    ,nOpcion: 0
    ,lVRet: false
    ,oParent: null
    ,oModel: null
    ,oStore: null
    ,oGrid: null
    ,oRecord: null
    ,oActividad: null

    ///
    /// EVENTS
    ///
    ,listeners:{
        destroy: function(){            
            if( this.oStore != null ){
                this.oStore.destroy();
            }

            if( this.oModel != null ){
                this.oModel.destroy();
            }

            if( this.oGrid != null ){
                this.oGrid.destroy();
            }

            if( this.oRecord != null ){
                this.oRecord.destroy();
            }

            if( this.oActividad != null ){
                this.oActividad = null;
            }

            if( this.oParent != null && this.oParent != 'undefined' && Ext.getClass(this.oParent).superclass.self.getName() === 'tBasicFrm'){
                if(!this.oParent.isVisible()){
                    this.oParent.show();
                }
            }
        }
        ,render: function(){
            if(this.oParent != null && this.oParent != 'undefined' && Ext.getClass(this.oParent).superclass.self.getName() === 'tBasicFrm' ){
                this.oParent.hide();
            }
        }
    }

    ///
    /// METHODS
    ///
    ,cargaActividad: function(){
        var oFecha = new Date();
        var oHora  = new Date();
        var nDia   = oFecha.getDate();
        var nMes   = oFecha.getMonth() + 1;
        var nAnyo  = oFecha.getFullYear();

        if( nDia < 10 ){
            nDia = '0' + nDia;
        }

        if( nMes < 10 ){
            nMes = '0' + nMes;
        }

        oFecha = nDia+'/'+nMes+'/'+nAnyo;
        oHora  = oHora.getHours() + ':' + oHora.getMinutes() + ':' + oHora.getSeconds();

        this.oActividad = { 
            cAlias: ""
            ,cTipo: ""
            ,cEstado: ""
            ,dFecha: oFecha
            ,cHoraIni: oHora
            ,cCodigo: ""
            ,cNumDoc: ""
            ,cTipoDoc: ""
            ,cImporte: ""
            ,cFPago: ""
            ,cEstado: ""
            ,cObserva: ""
            ,cImpresa: ""
        }
    }
    ,grabaActividad: function(){

    }
    ,Cerrar: function(){

    }
    ,Insertar: function(){

    }
    ,Modificar: function(){

    }
    ,Eliminar: function(){

    }
    ,Consultar: function(){

    }
    ,Imprimir: function(){

    }
    ,Filtrar: function(){

    }

    ///
    /// CONTROLS
    ///
    ,dockedItems: [
        {
            xtype: 'toolbar',
            dock: 'top',autoScroll: true,
            layout: {
                type: 'hbox',
                align: 'middle'
            },
            items: [
                {
                    xtype: 'button',
                    text: 'Cerrar',
                    width: 120,
                    icon: 'img/16x16/Salir16.png',
                    iconAlign: 'left',
                    listeners: {
                        click: 'Cerrar'
                    }
                },
                {
                    xtype: 'button',
                    text: 'Agregar',
                    width: 120,
                    icon: 'img/16x16/Añadir16.png',
                    iconAlign: 'left',
                    listeners: {
                        click: 'Insertar'
                    }
                },
                {
                    xtype: 'button',
                    text: 'Modificar',
                    width: 120,
                    icon: 'img/16x16/Editar16.png',
                    iconAlign: 'left',
                    listeners: {
                        click: 'Modificar'
                    }
                },
                {
                    xtype: 'button',
                    text: 'Consultar',
                    width: 120,
                    icon: 'img/16x16/Consultar16.png',
                    iconAlign: 'left',
                    listeners: {
                        click: 'Consultar'
                    }
                },
                {
                    xtype: 'button',
                    text: 'Eliminar',
                    width: 120,
                    icon: 'img/16x16/Eliminar16.png',
                    iconAlign: 'left',
                    listeners: {
                        click: 'Eliminar'
                    }
                }
            ]
        }
    ]
});

I cannot find the way to configure the button "Cerrar" listener to go to the class method "Cerrar". 我找不到配置按钮“Cerrar”监听器去方法“Cerrar”的方法。

I tried to scope all and no luck. 我试图扩大所有范围并且没有运气。

Can anybody help me? 有谁能够帮助我?

I've been playing around with this code and managed to get the button click handler to call the right function using the below listeners code but it doesn't quite feel right, Usually you can scope the buttons this to pass in the scope of the parent component but it does not seem to be working for me. 我一直在玩弄此代码,并设法按钮单击处理程序使用下面的听众代码来调用合适的功能,但它并不完全正确的感觉,通常你可以范围的按钮this在的范围内传递父组件,但它似乎不适合我。

I will keep investigating the scope method but in the meantime, you should be able to use either of these two methods: 我将继续调查范围方法,但在此期间,您应该能够使用以下两种方法之一:

// method 1
xtype: 'button',
...
listeners: {
    click: function() { this.up('panel').Cerrar(); }
}

// method 2
xtype: 'button',
...
listeners: {
    click: function() { this.ownerCt.ownerCt.Cerrar(); }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM