【问题标题】:extjs4 MVC listeners in controller控制器中的 extjs4 MVC 监听器
【发布时间】:2014-12-08 20:48:35
【问题描述】:

我在控制器中为我的系列图表的“itemmouseup”事件创建侦听器时遇到问题。

控制器:

init: function () {
    this.control({
        'monthbalance > chart': {
            render: this.onChartRendered,
            itemmouseup : this.onChartClick
        },          
    });
}, 

如果我插入“mouseup”事件而不是“itemmouseup”,它工作正常。但我需要'itemmouseup'。我哪里错了?

谢谢。

使用视图提取更新:

        },{
        id: 'card-1',
        xtype: 'chart',
        store: 'MonthBalances',
        title: 'This Year vs Previous Years',
        theme: 'Category1',
        legend: {position: 'right'},
        shadow: true,
        axes: [{
            type: 'Numeric',
            position: 'left',
            fields: ['monthbalance','monthlastyear','monthpreviousyear'],
            label: {
                renderer: Ext.util.Format.numberRenderer('0,0')
            },
            grid: true,
            minimum: 0
        },{
            type: 'Category',
            position: 'bottom',
            fields: ['month']
        }],

        series: [{
            type: 'line',
            title: 'this year',
            itemId: 'lineone',
            highlight: {
                size: 7,
                radius: 7
            },
            axis: 'left',
            xField: 'month',
            yField: 'monthbalance',
        //  listeners: {
        //      itemmouseup: function() {
        //          console.log('itemmouseup-thisyear');
        //      }
        //  },
        },{
            type: 'line',
            title: 'one year ago',
            itemId: 'linetwo',
            highlight: {
                size: 7,
                radius: 7
            },
            axis: 'left',
            xField: 'month',
            yField: 'monthlastyear',
        },{
            type: 'line',
            id: 'linethree',
            name: 'linethree',
            itemId: 'linethree',
            alias: 'widget.linethree',
            title: 'two years ago',
            highlight: {
                size: 7,
                radius: 7
            },
            axis: 'left',
            xField: 'month',
            yField: 'monthpreviousyear',

        }]
    }];

【问题讨论】:

    标签: extjs extjs4 extjs4.1 extjs4.2 extjs-mvc


    【解决方案1】:

    因为 Chart 没有 itemmouseup 事件。此事件仅适用于扩展 Ext.view.ViewExt.panel.Table 的类

    我认为您需要直接访问该系列,而不是访问该图表 持有该系列。将控件设置为您在图表中使用的系列本身,而不是图表。 您可以通过设置系列图表的 id 属性来执行此操作,以便您可以将控件绑定到该 id。

    // untested but it should work
    init: function () {
        this.control({
            '#your-id': {
                itemmouseup : this.onChartClick
            },          
        });
    }, 
    

    【讨论】:

    • 好的,我明白了。我让它作为我放置在视图中的监听器工作,就像在docs 中一样,但我真的希望它在我的控制器中。只能在视图中定义吗?
    • 我可以通过控制台中的Ext.ComponentQuery.query('.chart')[0].series.items 访问系列行,但无法弄清楚如何在控制器中的init 中访问它们。有任何想法吗?谢谢
    • @polarbear 我必须承认这是一个好问题......我没有时间深入挖掘,快速浏览 API 并没有多大帮助。只有一个提示;你可以通过它的 id 属性来访问它,你应该在这种情况下自己设置它。即使我不喜欢在这种情况下手动设置 id 也是必要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多