javascript - 从 extjs 4 中的 Accordion 和网格中获取值(value)

标签 javascript extjs extjs4 extjs4.1 extjs-grid

我想根据我的网格值参数制作一份pdf报告。我想从 Accordion 标题中获取年份作为参数编号 1,月份名称作为参数编号 2。但我做不到。谁能帮我解决这个问题。下面是我的代码:

Ext.define('Ext4Example.view.attendence.Timeperiod' ,{
    extend: 'Ext.form.Panel',
    alias : 'widget.timeperiod',
    id: 'timeperiod',
    region: 'west',
    border: true,
    width: 150,
    height:395,
    split: true,
    defaults: {
        // applied to each contained panel
        //bodyStyle: 'padding:15px'
    },
    layout: {
        // layout-specific configs go here
        type: 'accordion',
        titleCollapse: true,
        animate: true,
        activeOnTop: true,
        hideCollapseTool : true

    },

    initComponent: function() {
        var me = this;
        me.items = me.maccord();
        me.callParent(arguments);
    },
    mstore: function(year){
        var data = [
            [1,  year, 'January'  ],
            [2,  year, 'February' ],
            [3,  year, 'March'    ],
            [4,  year, 'April'    ],
            [5,  year, 'May'      ],
            [6,  year, 'June'     ],
            [7,  year, 'July'     ], 
            [8,  year, 'August'   ], 
            [9,  year, 'September'], 
            [10, year, 'October'  ], 
            [11, year, 'November' ], 
            [12, year, 'December' ]
        ];

        var store = Ext.create('Ext.data.ArrayStore', {
            storeId: 'mstore',
            fields: [              
                {name: 'id', type: 'int'},
                {name: 'year', type: 'int'},
                {name: 'month', type: 'string'}
            ],
            data:data
        });
        return store;
    },
    mpanel: function(year){
        var me = this,
        mpanel = new Ext.grid.Panel({
            border: false,
            viewConfig: {
                stripeRows: true
            },
            hideHeaders: true,
            columns: [
                { text: 'month',  dataIndex: 'month', flex: 1},
                { menuDisabled    : true,
                    sortable        : false,
                    xtype           : 'actioncolumn',
                    width           : 24,
                    items           : [{
                            icon        : "${resource(dir: 'images', file: 'PDF01001.png')}",
                            hide        : true,
                            tooltip     : 'Print PDF Report of this Month?',
                            handler     : function(record) {
                                          alert(record.data.month)
                            }
                        }]
                }
            ],
            listeners:{
                selectionchange:function(model, records ) {
                    var store = Ext.data.StoreManager.lookup('Attendences');
                    var record = records[0];
                    store.load({
                        filters: [
                            {property:'month', value:record.data.id},
                            {property:'year', value:record.data.year}
                        ]          
                    });                    
                }
            },
            store: me.mstore(year),
            width: 150
        });
        return mpanel;
    },
    maccord: function(){          
        var year = ${(new Date()).format('yyyy')},
        limit = year - 5,
        me = this,
        maccord = [];

        for(year; year > limit ; year--){
            maccord.push({
                title: 'Year '+ year,
                ident: 'accordion-panel',
                items: me.mpanel(year)              
            });
        }
        return maccord;
    }
});

最佳答案

月份和年份在您的记录中。您不需要从 Accordion 标题中获取年份。您的问题是,记录不是处理程序中的第一个参数:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.column.Action-cfg-handler

items: [{
   icon: 'test',
   tooltip: 'Print PDF Report of this Month?',
   scope: this,
   handler: function(view, rowIndex, colIndex, item, e, record) {
        alert(record.data.month + "/" + record.data.year);
   }
}]

可以看看:http://jsfiddle.net/AMx6r/1279/

关于javascript - 从 extjs 4 中的 Accordion 和网格中获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13794947/

相关文章:

javascript - JQuery 滚动监听器

javascript - 通过 this 对对象的属性进行 Jquery 函数

javascript - 根据最新的 2020 年 1 月版本,我如何倾斜/旋转 horizo​​nata/垂直条形图的 hAxis 和 vAxis 文本

extjs - 如何在 ExtJs4 中收听用户对文本字段代码所做的编辑和更改?

javascript - Extjs 存储查找所有

ExtJS 6 - 如何在不使用表单的情况下上传文件?

javascript - 使用 requirejs 加载模块的前缀

javascript - 标签和字段在同一行的 ExtJS 表单

javascript - Sencha touch 2 中的音频和视频并非始终失败

Extjs checkcolumn 根据值禁用某些行