Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.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 选中CheckboxGroup ExtJS组件中的各种复选框_Javascript_Extjs_Checkbox_Extjs4 - Fatal编程技术网

Javascript 选中CheckboxGroup ExtJS组件中的各种复选框

Javascript 选中CheckboxGroup ExtJS组件中的各种复选框,javascript,extjs,checkbox,extjs4,Javascript,Extjs,Checkbox,Extjs4,我正在寻找如何检查Ext.form.CheckboxGroup组件中的项目的解决方案,该组件已呈现并包含一组项目 组件的代码为: var oCheckboxGroup = new Ext.form.CheckboxGroup({ columns: 2, vertical: true, items: [ {boxLabel: "Value 1", inputValue: 1}, {boxLabel: "Value 2", inputValue

我正在寻找如何检查Ext.form.CheckboxGroup组件中的项目的解决方案,该组件已呈现并包含一组项目

组件的代码为:

var oCheckboxGroup = new Ext.form.CheckboxGroup({
    columns: 2,
    vertical: true,
    items: [
        {boxLabel: "Value 1", inputValue: 1},
        {boxLabel: "Value 2", inputValue: 2},
        ...
        {boxLabel: "Value N", inputValue: N}
    ]
});
该组件将通过单击按钮显示在模式窗口中,因此我必须根据要修改的记录重新检查checkboxgroup中的项目

例如,当我第一次显示窗口时,我必须在第二次预检项目1、2和3–2、4和5

所以真正的问题是:如何循环检查复选框组项目和选中/取消选中复选框

顺便说一句,我尝试了下一个解决方案,但没有:

oCheckboxGroup.items.each(function(oEl) {
    oEl.checked = true;
});
谢谢

UPD

找到答案。问题将在2天后结束,我将被允许接受我自己的答案,或者如果其他人正确回答extjs3.x,则提前结束 在CheckboxGroup对象上使用setValue方法,并为其中的各个项目指定true/false:

setValue( Object value ) 
例如,在您的情况下,要预先检查1、2、3,您必须致电:

cbxGrpObj.setValue([true,true,true]);
cbxGrpObj.setValue([false,false,false, true,true]);
要预检查4,5和取消检查1,2,3,您必须致电:

cbxGrpObj.setValue([true,true,true]);
cbxGrpObj.setValue([false,false,false, true,true]);
希望这有帮助

对于extjs3.x 在CheckboxGroup对象上使用setValue方法,并为其中的各个项目指定true/false:

setValue( Object value ) 
例如,在您的情况下,要预先检查1、2、3,您必须致电:

cbxGrpObj.setValue([true,true,true]);
cbxGrpObj.setValue([false,false,false, true,true]);
要预检查4,5和取消检查1,2,3,您必须致电:

cbxGrpObj.setValue([true,true,true]);
cbxGrpObj.setValue([false,false,false, true,true]);

希望这有帮助

找到了解决方案。森查说:

setValueObject值:Ext.form.CheckboxGroup

设置组中所有复选框的值。预期格式是与组中复选框的名称相对应的名称-值对对象。每对都可以有一个或多个值:

单个布尔值或字符串值将传递给具有该名称的复选框的setValue方法。有关接受的值,请参见Ext.form.field.Checkbox.setValue中的规则。 字符串值数组将与具有该名称的组中复选框的inputValue匹配;数组中存在inputValue的复选框将被选中,其他复选框将被取消选中。 所以我只是将name:cbgroup属性添加到checkbox-configs中,然后使用如下构造

// first time
oCheckboxGroup.setValue({
    cbgroup: [1, 2, 3]
})
// second time
oCheckboxGroup.setValue({
    cbgroup: [2, 4, 5]
})

感谢所有试图帮助我的人,希望这个答案能节省别人的时间

找到了解决方案。森查说:

setValueObject值:Ext.form.CheckboxGroup

设置组中所有复选框的值。预期格式是与组中复选框的名称相对应的名称-值对对象。每对都可以有一个或多个值:

单个布尔值或字符串值将传递给具有该名称的复选框的setValue方法。有关接受的值,请参见Ext.form.field.Checkbox.setValue中的规则。 字符串值数组将与具有该名称的组中复选框的inputValue匹配;数组中存在inputValue的复选框将被选中,其他复选框将被取消选中。 所以我只是将name:cbgroup属性添加到checkbox-configs中,然后使用如下构造

// first time
oCheckboxGroup.setValue({
    cbgroup: [1, 2, 3]
})
// second time
oCheckboxGroup.setValue({
    cbgroup: [2, 4, 5]
})

感谢所有试图帮助我的人,希望这个答案能节省别人的时间

我只是在寻找如何从form.setValues调用中设置checkboxgroup值时偶然发现了这个问题。事实证明,在ExtJS中,如果给组中的所有复选框取相同的名称,则只需给setValues一个该名称的值数组,就可以为您检查任何匹配的值

var oCheckboxGroup = new Ext.form.CheckboxGroup({
    columns: 2,
    vertical: true,
    items: [
        {name: 'cbg1', boxLabel: "Value 1", inputValue: 1},
        {name: 'cbg1', boxLabel: "Value 2", inputValue: 2},
        {name: 'cbg1', boxLabel: "Value N", inputValue: N}
    ]
});
...

form.setValues( { cbg1: [ '1','N' ] } );

我希望这能帮助其他使用与我相同的关键字找到它的人。

我只是在寻找如何从form.setValues调用中设置checkboxgroup值时偶然发现了这一点。事实证明,在ExtJS中,如果给组中的所有复选框取相同的名称,则只需给setValues一个该名称的值数组,就可以为您检查任何匹配的值

var oCheckboxGroup = new Ext.form.CheckboxGroup({
    columns: 2,
    vertical: true,
    items: [
        {name: 'cbg1', boxLabel: "Value 1", inputValue: 1},
        {name: 'cbg1', boxLabel: "Value 2", inputValue: 2},
        {name: 'cbg1', boxLabel: "Value N", inputValue: N}
    ]
});
...

form.setValues( { cbg1: [ '1','N' ] } );
Ext.each(`oCheckboxGroup`.items.items, function(item) {
     item.checked = true;
}, this);

我希望这有助于找到与我相同关键字的其他人。

谢谢你的回答。这是不正确的,但它帮助我找到了解决方案=Sencha的setValue文档说,数组中存在inputValue的复选框将被选中,其他复选框将被取消选中…我应该询问您正在使用的ExtJS版本!!我提到的解决方案适用于3.x版本。谢谢你的回答。这是不正确的,但它帮助我找到了解决方案=Sencha的setValue文档说,数组中存在inputValue的复选框将被选中,其他复选框将被取消选中…我应该询问您正在使用的ExtJS版本!!我提到的解决方案..适用于3.x版本。@ajit.kumar yep,你是对的,这就是为什么我用extjs4标记问题@是的,这就是为什么我用extjs4标记这个问题;
Ext.each(`oCheckboxGroup`.items.items, function(item) {
     item.checked = true;
}, this);