3

我有以下问题。我有网格tbar。里面tbar我有数量Ext.form.field.Trigger

当用户单击触发按钮时,我想使用提供的功能过滤商店grid。我想定义triggerclick内部定义的功能class,所以我可以用不同的方式重用这个组件grid

所以,简而言之,我想找到放置被点击组件的面板并调用面板函数,或者将面板的引用传递triggerclick给更好的方法来实现这一点。

代码(FilterField -> 触发器扩展):

Ext.define('GSIP.core.components.FilterField', {
    extend: 'Ext.form.field.Trigger',
    alias: 'widget.filterfield',
    initComponent: function() {

        this.addEvents('filterclick');
        this.callParent(arguments);
    },
    onTriggerClick: function(e, t) {

        //Ext.getCmp('gsip_plan_list').filterList(); - working but dont want this

        //this.fireEvent('filterclick'); - controller cant see it,

        //this.filterList; - is it possible to pass scope to panel or reference to panel

        //e.getSomething() - is it possible to get panel via EventObject? smth like e.getEl().up(panel)


    }
});

面板代码:

Ext.define('GSIP.view.plans.PlanReqList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.gsip_devplan_list',
    id: 'gsip_plan_list',
    title: i18n.getMsg('gsip.view.PlanReqList.title'),
    layout: 'fit',
    initComponent: function() {

        this.store = 'DevPlan';

        this.tbar = [{
            xtype: 'filterfield',
            id: 'filter_login',
            triggerCls: 'icon-user',
            //scope:this - how to pass scope to panel without defining onTriggerClick here
            //          onTriggerClick: function() { 
            //              this.fireEvent('filterclick'); //working event is fired but controller cant see it
            //              this.filterList; //this is working but i dont want to put this code in every filterfield
            //          },
            //          listeners : {
            //              filterclick: function(btn, e, eOpts) { //this is working

            //              }
            //            },
        }];

        this.columns = [{
            id: 'id',
            header: "Id",
            dataIndex: "id",
            width: 50,
            sortable: true,
            filterable: true
        }, {
            header: "Name",
            dataIndex: "name",
            width: 150,
            sortable: true,
            filterable: true
        }, {
            header: "Author",
            dataIndex: "author",
            sortable: true,
            renderer: this.renderLogin,
            filterable: true
        }];

        this.callParent(arguments);


    },
    filterList: function() {
        this.store.clearFilter();

        this.store.filter({
            property: 'id',
            value: this.down("#filter_id").getValue()
        }, {
            property: 'name',
            value: this.down("#filter_name").getValue()
        });
    },
    renderLogin: function(value, metadata, record) {
        return value.login;
    }
});

控制器部分代码:

init: function() {
    this.control({
        'attachments': {
            filesaved: this.scanSaved,
        }
    }, {
        'scan': {
            filesaved: this.attachmentSaved
        }
    }, {
        '#filter_login': {
            filterclick: this.filterStore //this is not listened 
        }
    });
},
filterStore: function() {
    console.log('filtering store');

    this.getPlanListInstance().filter();
},
4

1 回答 1

3

控制器可以听任何东西。只需要准确指定要做什么。但我会在面板级别触发事件 - 将其添加到您的触发器处理程序中:

this.up('panel').fireEvent('triggerclicked');
于 2012-07-17T14:48:00.500 回答