Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取复选框的值_Javascript_Extjs - Fatal编程技术网

Javascript 如何获取复选框的值

Javascript 如何获取复选框的值,javascript,extjs,Javascript,Extjs,如何获取复选框的值 var tb = new Ext.Toolbar(); tb.add({ xtype: 'checkbox', boxLabel: 'Expand Groups by Default', id: 'GetChkBoxValue', checked: true, handler: function() {

如何获取复选框的值

var tb = new Ext.Toolbar();

tb.add({
                xtype: 'checkbox',
                boxLabel: 'Expand Groups by Default',
                id: 'GetChkBoxValue',
                checked: true,
                handler: function() {
                    alert(this.getValue())
                }
       });
是否有可能在tb之外获取复选框的值。我做过类似的操作,但它没有启动

Ext.getCmp('GetChkBoxValue').getValue(); 

请尝试以下代码,它应该可以工作:

new Ext.Window({
    renderTo: Ext.getBody(),
    width: 500,
    height: 200,
    title: 'test window',
    items: [{
       xtype: 'checkbox',
       boxLabel: 'Expand Groups by Default',
       id: 'chkid',
       checked: true
    }]
}).show()
Ext.getCmp('chkid').getValue()

然后使用复选框和getValue()获得其状态(选中或未选中)。快乐的ExtJS编码

以下是对我有效的方法:

var expandAllGroupsCheckbox = Ext.create(

            {
                xtype: 'checkbox',
                boxLabel: 'Expand Groups by Default',
                id: 'chkid',
                checked: true,
                afterRender: function() {
                    Ext.form.Checkbox.superclass.afterRender.call(this);
                    alert(this.getValue());// giving true 
                    this.checkChanged();
                },
                checkChanged: function()
                {
                    var checked = expandAllGroupsCheckbox.getValue();
                    gv.startCollapsed = !checked;
                    if ( gv.mainBody )
                    {
                        gv.toggleAllGroups( !checked );
                    }
                },
                listeners: {
                    check: {
                        fn: function(){expandAllGroupsCheckbox.checkChanged()}
                    }
                }

            });
然后:

tbar: [
               expandAllGroupsCheckbox
,
                    {
                        xtype: 'tbbutton',
                        icon: '/images/icon_list_props.gif',
                        handler: function() {
                            ShowPreferencesPage();
                        }
                    }
],
仅此而已:

var cbox = Ext.getCmp('cboxId');
alert(cbox.checked);

发生了什么事?错误?您创建的代码应该可以工作。我能想到的唯一一件事是,您正在尝试在呈现工具栏之前调用getValue。由于您的复选框是按需创建的(通过传入cfg对象),Ext.getCmp在呈现元素之前不会找到该元素。是的,问题是它总是给我false,因为对象是实例化的,并且在呈现之前被调用。我想知道如何获取复选框的值??我可以访问网格面板中复选框的值,如下所示Ext.getCmp('chkid')。getValue()使用此值如果为真,我必须检查组,如果为假,我必须折叠组。有人能帮我展开和折叠网格面板中的组吗。