如何从Extjs中的控制器调用视图的侦听器 [英] how to call a listener of view from controller in Extjs

查看:138
本文介绍了如何从Extjs中的控制器调用视图的侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图中有一个条形图,其中有一个侦听器正在检索条形列项目,现在我必须从控制器中调用该侦听器,这是我的代码...

i have a bar chart in my view where i have a listener which is retrieving the bar column items ,now i have to call that listener from controller here is my code ...

我认为这是侦听器.

listeners: {
    itemmousedown: function (obj) {
        alert(obj.storeItem.data['source'] + ' &' + obj.storeItem.data['count']);
    }
},

我必须从控制器中调用此侦听器.这是我的代码.

and i have to call this listener from my controller.here is my code..

init: function () {
    this.control({
        'barColumnChart': { //this is the id of the bar chart in my View
            click: function () {

            }
        }
    });
},

推荐答案

itemmousedown事件由系列"触发,该系列不是组件,仅在布局后由图表初始化.因此,为了获得对系列对象的引用,我们需要等待图表的afterlayout事件.但是不幸的是,该图表没有触发一个后备事件. 因此,首先重写图表的afterComponentLayout方法,以使其触发事件:

The itemmousedown event is fired by the "series", and the series is not a component, and is only initialized by the chart after layout. So in order to get a reference to the series object we need to wait for the afterlayout event of the chart. But unfortunately the chart is not firing an afterlayout event... So, first override the afterComponentLayout method of chart, such that it fires the event:

Ext.define('MyNewChart',{
    extend: 'Ext.chart.Chart',
    afterComponentLayout: function(width, height, oldWidth, oldHeight) {
        this.callParent(arguments);
        this.fireEvent('afterlayout', this);
    }
});

现在,使用我们的新图表类来创建您的图表:

Now, use our new chart class to create your chart:

Ext.create('MyNewChart', {
     id: 'myChart',
     ...
});

现在我们可以创建一个控制器,该控制器实际上在itemmousedown事件上创建一个侦听器:

And now we can create a controller that actually create a listener on the itemmousedown event:

Ext.define('Gamma.controller.ControlFile', {
    extend : 'Ext.app.Controller',
    initializedEvents: false,
    init: function() {
        this.control({
            '#myChart': {
                afterlayout: this.afterChartLayout
            }
        });
    },
    afterChartLayout: function(){
        if(this.initializedEvents==true) return;
        this.initializedEvents=true;
        Ext.getCmp('myChart').series.items[0].on('itemmousedown',function(obj){
            console.log(obj);
        });
    }
});

这是一个有效的小提琴: http://jsfiddle.net/qjfBC/

Here is a working fiddle: http://jsfiddle.net/qjfBC/

这篇关于如何从Extjs中的控制器调用视图的侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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