从控制器设置触发器值

时间:2012-08-01 03:48:59

标签: model-view-controller extjs extjs4

我尝试通过触发器字段点击来显示窗口网格中的数据。 这是我使用triggerfield的表单:

Ext.define('ResApp.view.group.Detail', {
extend: 'Ext.window.Window',
alias:'widget.groupdetail',

floating: true,
hidden: false,
width: 450,
//height: 400,
resizeable: false,
title: 'Detail Group',
modal: true,

initComponent: function() {
    var me = this;

    Ext.applyIf(me, {

        ....other config...

        items: [
            {
                xtype: 'form',
                itemId: 'groupDetailForm',
                border: false,
                layout: {
                    type: 'auto'
                },
                bodyPadding: 10,
                preventHeader: true,
                title: 'My Form',
                items: [

                    ....other items...

                    {
                        xtype: 'triggerfield',
                        padding: '0 0 5 0',
                        width: 350,
                        fieldLabel: 'Nama Kontak',
                        name: 'namaJamaah',
                        itemId: 'namaLead',
                        triggerCls: ' x-form-search-trigger',
                        onTriggerClick: function(){
                            Ext.widget('listjamaahgroup').show();
                        }
                    },

                    ....other items...

                ]
            }
        ]
    });

    me.callParent(arguments);
}});

接下来,我的窗口用网格列出数据:

Ext.define('ResApp.view.group.ListJamaahGroup', {
extend: 'Ext.window.Window',
alias:'widget.listjamaahgroup',

height: 400,
width: 750,
title: 'Daftar Jamaah',
modal: true,
hidden: false,
floating: true,
resizeable: false,

initComponent: function() {
    var me = this;

    Ext.applyIf(me, {
        items : [
            {
                    xtype: 'gridpanel',
                    autoScroll: true,
                    border:false,
                    title: 'Daftar Anggota',
                    itemId: 'gridAnggota',
                    preventHeader: true,
                    forceFit: true,
                    flex: 1,
                    store: 'Jamaah',
                    allowDeselect : true,
                    viewConfig: {
                        autoScroll: true
                    },
                    dockedItems: [
                        {
                            xtype: 'toolbar',
                            dock: 'top',
                            cls:'border-bottom',
                            items: [
                                {
                                    xtype: 'button',
                                    text: 'Pilih',
                                    iconCls:'edit',
                                    action: 'selectJamaahGrp',
                                    itemId: 'selectJamaahGrp'
                                },
                                {
                                    xtype: 'button',
                                    text: 'Baru',
                                    iconCls:'add'
                                }
                            ]
                        }
                    ],
                    columns: [

                    ....Grid columns...

                    ]                            
            }
        ]

    });

    me.callParent(arguments);
}});

这是我的控制者:

Ext.define('ResApp.controller.GroupDetails', {
extend: 'Ext.app.Controller',
stores: [
    'Group', 'Jamaah'
],
models: [
  'Group', 'Jamaah'
],
views:[
    'group.Detail',
    'group.ListJamaahGroup'
],
init: function(){
    this.control({
        ...

        'button[action=selectJamaahGrp]': {
            click: this.selectJamaahGrp
        },

        ...
    });
},

... other functions ...

selectJamaahGrp: function(button, e, options) {
    //windowDetail.hide();

    var grid = button.up('grid');
    if (grid) {
        var windowDetail = Ext.widget('groupdetail');
        var form = windowDetail.down('form');


        var sm = grid.getSelectionModel();
        var rs = sm.getSelection();
        if (!rs.length) {
            Ext.Msg.alert('Info', 'Pilih salah satu');
            return;
        }

        var data = grid.getSelectionModel().getSelection()[0];
        //how to setValue to triggerfield from here
    }
    button.up('listjamaahgroup').destroy();
},
batalSelClick: function(button, e, options) {
    button.up('listjamaahgroup').destroy();
}
... other functions ...})

我的问题是,我无法想象如何从我的控制器setValue触发器。还是有另一种方法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

只需在控制器中定义参考号(refs: [ { ref: 'trigger', selector: 'triggerfield' } ]),然后执行this.getTrigger().setValue()