开发者

How to obtain a reference to a Checkbox in a toolbar?

开发者 https://www.devze.com 2022-12-08 03:07 出处:网络
Could someone tell me the preferred way of getting a reference to checkbox if its in a toolbar in an EditorGridPanel? I simply would like to call the getValue() on it so I can do stuff with it.

Could someone tell me the preferred way of getting a reference to checkbox if its in a toolbar in an EditorGridPanel? I simply would like to call the getValue() on it so I can do stuff with it.

My EditorGridPanel is built similar to the one below (plus a few more config properties):

var grid = new Ext.grid.EditorGridPanel({    
tbar: new Ext.Toolbar({
            width: 200,
            he开发者_如何学JAVAight: 30,
            items: [
                {
                    xtype: 'checkbox',
                    name: 'field1',
                    boxLabel: 'Order aktiverad'
                }
            ]
        })
 });

Thanks!


Can't you just give the checkbox an itemId, and use getCmp()?


use the "ref" config like this:

var grid = new Ext.grid.EditorGridPanel({    
tbar: new Ext.Toolbar({
            width: 200,
            height: 30,
            items: [
                {
                    xtype: 'checkbox',
                    name: 'field1',
                    boxLabel: 'Order aktiverad',
                    ref: '../myCheckbox'
                }
            ]
        })
});

var checkboxValue = grid.myCheckbox.getValue();

See also the "ref" config option here: http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Component


Thanks for the answer. Pushed me in the right direction; I didn't even know about getCmp().

Tried Ext.getCmp() with the itemId but it didn't find it. I gave it an id and that worked:

tbar: [
                {
                    xtype: 'checkbox',
                    name: 'field1',
                    boxLabel: 'Order aktiverad',

                    id : 'cb_order_active'
                },
                {
                    //Button        
                    text: 'Test',
                    handler : function(){
                        alert(Ext.getCmp('cb_order_active').getValue());
                    }
                }
            ]


itemId is supposed to be used with the container in which the component which you want to access is rendered. Also, for itemId you should use the getComponent() function instead of getCmp().

So, if you have component with itemId "a", which is in the container "c" then you can access "a" using

c.getComponent('a')

Following link explains the difference between id and itemId.

http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.Checkbox-cfg-itemId

0

精彩评论

暂无评论...
验证码 换一张
取 消