Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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 无法在extjs窗口中获取checkboxgroup的值_Javascript_Extjs_Checkbox - Fatal编程技术网

Javascript 无法在extjs窗口中获取checkboxgroup的值

Javascript 无法在extjs窗口中获取checkboxgroup的值,javascript,extjs,checkbox,Javascript,Extjs,Checkbox,我有一个ExtJS窗口,其中包含checkboxgroups,还有一个按钮来获取所选的值 我带了两个伊瑟斯。代码如下: Ext.create('widget.window', { title : 'Select which scenario to run', draggable: true, modal: true, header : { titlePosition : 2,

我有一个ExtJS窗口,其中包含
checkboxgroup
s,还有一个按钮来获取所选的值

我带了两个伊瑟斯。代码如下:

Ext.create('widget.window', 
    {
        title  : 'Select which scenario to run',
        draggable: true,
        modal: true,
        header : 
        {
            titlePosition : 2,
            titleAlign    : 'center'
        },
        closable    : true,
        closeAction : 'hide',
        width       : 400,
        height      : 350,
        x           : contentPanel.getX() + 50,
        y           : contentPanel.getY() + 50,
        layout: {
        type: 'hbox',
        align: 'stretch'
        },
        items: 
        [
            {
                xtype: 'panel',
                title: 'If success',
                itemId : 'success',
                autoScroll:true,
                flex: 1,
                items:
                [{
                    xtype: 'checkboxgroup',
                    columns: 1,
                    vertical:true,
                    items: 
                    [
                        { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
                        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
                        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
                        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
                        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
                        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
                        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
                        { boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
                        { boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
                    ]
                }]
            },
            {
                xtype: 'panel',
                title: 'If failure',
                id: 'failure',
                autoScroll:true,
                flex: 1,
                items:
                [{
                    xtype: 'checkboxgroup',
                    columns: 1,
                    vertical:true,
                    items: 
                    [
                        { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
                        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
                        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
                        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
                        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
                        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
                        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
                        { boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
                        { boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
                    ]
                }]
            }
        ],
        buttons:
        [{
            text    : 'Save',
            itemId  : 'if_save',
            icon    : '../images/save.png',
            ui      : 'default',
            handler : function()
            {
                var cb_f = Ext.getCmp('failure').getValue()
                alert(JSON.stringify(cb_f));
            }
        }]

    }).show(); 
在按钮处理程序中,我想从复选框中获取所选项目
我试过
这个.getComponent('success').getValue()
Ext.getCmp('failure').getValue()
,但firebug一直说它们没有定义

因此,如何获取“保存”单击的值?

谢谢

这应该可以:

listeners: 
{
    change: function(field, newValue, oldValue, eOpts)
    {
       console.log(newValue.rb);
    }
}
这应该起作用:

listeners: 
{
    change: function(field, newValue, oldValue, eOpts)
    {
       console.log(newValue.rb);
    }
}
根据: ,我建议如下:

使用Id扩展您的复选框组:

[{
    xtype: 'checkboxgroup',
    id: 'myGroup',
    columns: 1,
    vertical: true,
    items:
    [
        { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
        { boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
        { boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
    ]
}]
以便您以后可以通过选择器获取所选项目:

buttons:
[{
    text: 'Save',
    itemId: 'if_save',
    icon: '../images/save.png',
    ui: 'default',
    handler: function () {
        var group = Ext.getCmp('myGroup');
        var checkedArray = group.query('[checked="true"]');

        var cb_f = Ext.getCmp('failure').getValue();
        alert(JSON.stringify(cb_f));
    }
}]
希望这个答案也有帮助

根据: ,我建议如下:

使用Id扩展您的复选框组:

[{
    xtype: 'checkboxgroup',
    id: 'myGroup',
    columns: 1,
    vertical: true,
    items:
    [
        { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
        { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
        { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
        { boxLabel: 'Item 4', name: 'rb', inputValue: '4' },
        { boxLabel: 'Item 5', name: 'rb', inputValue: '5' },
        { boxLabel: 'Item 6', name: 'rb', inputValue: '6' }
    ]
}]
以便您以后可以通过选择器获取所选项目:

buttons:
[{
    text: 'Save',
    itemId: 'if_save',
    icon: '../images/save.png',
    ui: 'default',
    handler: function () {
        var group = Ext.getCmp('myGroup');
        var checkedArray = group.query('[checked="true"]');

        var cb_f = Ext.getCmp('failure').getValue();
        alert(JSON.stringify(cb_f));
    }
}]
希望这个答案也有帮助

尝试以下操作:

    buttons:
    [{
        text    : 'Save',
        itemId  : 'if_save',
        icon    : '../images/save.png',
        ui      : 'default',
        handler : function()
        {
            var cb_f = Ext.getCmp('failure').getValue()["rb"];
            alert(cb_f);
        }
    }]
handler : function()
{
  var selectedSuccessValues = Ext.getCmp('SUCCESS_CHECKBOX_ID').getChecked();               
  for(var i=0;i<selectedSuccessValues.length;i++)
  {
    alert(selectedSuccessValues[i].inputValue);
  }             
}
请尝试以下操作:

    buttons:
    [{
        text    : 'Save',
        itemId  : 'if_save',
        icon    : '../images/save.png',
        ui      : 'default',
        handler : function()
        {
            var cb_f = Ext.getCmp('failure').getValue()["rb"];
            alert(cb_f);
        }
    }]
handler : function()
{
  var selectedSuccessValues = Ext.getCmp('SUCCESS_CHECKBOX_ID').getChecked();               
  for(var i=0;i<selectedSuccessValues.length;i++)
  {
    alert(selectedSuccessValues[i].inputValue);
  }             
}

例如,如果为checkboxgroup创建id

xtype: 'checkboxgroup',
id: 'SUCCESS_CHECKBOX_ID',
columns: 1,
vertical:true,
items: 
[
  { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
  { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
  { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }
]
您可以执行以下操作:

    buttons:
    [{
        text    : 'Save',
        itemId  : 'if_save',
        icon    : '../images/save.png',
        ui      : 'default',
        handler : function()
        {
            var cb_f = Ext.getCmp('failure').getValue()["rb"];
            alert(cb_f);
        }
    }]
handler : function()
{
  var selectedSuccessValues = Ext.getCmp('SUCCESS_CHECKBOX_ID').getChecked();               
  for(var i=0;i<selectedSuccessValues.length;i++)
  {
    alert(selectedSuccessValues[i].inputValue);
  }             
}
处理程序:函数() { var selectedSuccessValues=Ext.getCmp('SUCCESS_CHECKBOX_ID')。getChecked();
例如,如果为checkboxgroup创建一个id,则为(var i=0;i)

xtype: 'checkboxgroup',
id: 'SUCCESS_CHECKBOX_ID',
columns: 1,
vertical:true,
items: 
[
  { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
  { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
  { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }
]
您可以执行以下操作:

    buttons:
    [{
        text    : 'Save',
        itemId  : 'if_save',
        icon    : '../images/save.png',
        ui      : 'default',
        handler : function()
        {
            var cb_f = Ext.getCmp('failure').getValue()["rb"];
            alert(cb_f);
        }
    }]
handler : function()
{
  var selectedSuccessValues = Ext.getCmp('SUCCESS_CHECKBOX_ID').getChecked();               
  for(var i=0;i<selectedSuccessValues.length;i++)
  {
    alert(selectedSuccessValues[i].inputValue);
  }             
}
处理程序:函数() { var selectedSuccessValues=Ext.getCmp('SUCCESS_CHECKBOX_ID')。getChecked(); 对于(var i=0;i