我有一个带有MVC模型的应用程序,在视图中,我用侦听器创建了一个滑块,但是我希望侦听器在controller类中,并且我想获取元素的ID,但它是由变量生成的从树面板上...

这是代码

Ext.require('Ext.slider.*');

Ext.define('app.view.ViewTablaContenido', {
extend: 'Ext.window.Window',
id: 'viewTablaContenido',
shadow: false,
alias: 'widget.tablaContenido',

initComponent: function() {

    var anchoPanatallaRes = window.screen.width;
    var altoPantallaRes = window.screen.height;

    var anchoTOC = 330;
    var altoTOC = 473;

    if (anchoPanatallaRes <= 1024) {
        anchoTOC = 282;
        altoTOC = 373;
    }

    function addUrl(value, p, record) {
        return value ? Ext.String.format(
                '<a href="'+value+'"target="_blank"'+'>Ver metadato'+'</a>'
        ):'';
    }

    var treeStore = Ext.getStore('capa');

    var tree = Ext.create('Ext.tree.Panel', {
        title: '',
        id: "arbolTabla",
        width: anchoTOC,
        height: altoTOC,
        reserveScrollbar: true,
        loadMask: true,
        useArrows: true,
        rootVisible: false,
        store: 'capa',
        allowDeselect : true,
        border : true,
        animate: true,
        columns: [{
            xtype: 'treecolumn',
            text: 'Capa',
            flex: 5,
            sortable: true,
            dataIndex: 'titulo'
        },{
            text: 'Metadato',
            flex: 2,
            dataIndex: 'metadato',
            renderer: addUrl
        }],

        tbar: [{
            labelWidth: 100,
            xtype: 'triggerfield',
            id: 'campoBusquedaCapa',
            fieldLabel: 'Nombre capa:',
            triggerCls: 'x-form-clear-trigger',
            onTriggerClick: function() {
                this.reset();
                treeStore.clearFilter();
                this.focus();
            },
            enableKeyEvents: true
        }, {
            xtype : 'button',
            width: 20,
            height: 25,
            id : 'btnApagarCapas',
            action: 'apagarCapas',
            tooltip : 'Apagar todas las capas',
            padding:0
        }]
    });

    Ext.apply(this, {
        title: 'TABLA CONTENIDO',
        constrain: true,
        header : {
            titlePosition : 2,
            titleAlign : 'center'
        },
        closable : false,
        width : anchoTOC,
        height : altoTOC,
        x : 20,
        y : 270,
        layout : 'fit',
        animCollapse : true,
        collapsible : true,
        collapseDirection : Ext.Component.DIRECTION_LEFT,
        items: [tree],
    });

    tree.on('itemcontextmenu', function(view, record, item, index, event, eOpts) {
        event.stopEvent();
        if (record.data.leaf != false) {

             slider = Ext.create('Ext.slider.Single', {
                id: record.data.id,
                hideLabel: true,
                floating: true,
                width: 200,
                minValue: 0,
                maxValue: 100,
                value : 70,
                //listeners: {
                    //change: function (newValue, thumb, eOpts ){
                        //var capaBuscar = record.data.id;
                        //var controladorUbicar = aplicacion.getController("ControlUbicar");
                        //var capa =  controladorUbicar.buscarcapa(capaBuscar);
                        //capa.setOpacity(thumb/100);
                    //},
                    //blur: function() {
                        //slider.setVisible(false);
                        //capaBuscar=null;
                    //}
                //}
             });
            slider.showBy(item, 'tl-tl', [event.getX() - view.getX(), 12]);
        }
    }, this);
    this.callParent(arguments);
}
});

最佳答案

将此监听器添加到您的控制器:

Ext.define('Fiddle.controllers.MyController',{
    extend : 'Ext.app.Controller',
    alias: 'controller.mycontroller',
    init : function() {
        this.control({
            "slider" : {
                change : function (slider, newValue, thumb, eOpts  ) {
                    var capa = this.buscarcapa(slider.record.get('id'));
                    if (capa) capa.setOpacity(thumb/100);
                },
                blur: function(slider, event, eOpts) {
                     slider.setVisible(false);
                }
            }
        });
    },
    buscarcapa : function (id) {
        return false;
    }
});


并创建如下滑块:

listeners : {
    'itemcontextmenu' : function(view, record, item, index, event, eOpts) {
        event.stopEvent();
        if (record.data.leaf != false) {
            console.log(item);
            slider = Ext.create('Ext.slider.Single', {
                record : record,
                hideLabel: true,
                floating: true,
                type : 'capaControl',
                width: 200,
                minValue: 0,
                maxValue: 100,
                value : 70
            });
            slider.showBy(item, 'tl-tl', [event.getX() - view.getX(), 12]);
        }
    }
}


检查这个小提琴:https://fiddle.sencha.com/#fiddle/odd

09-20 06:57