gpt4 book ai didi

javascript - 检查 CheckboxGroup ExtJS 组件中的各种复选框

转载 作者:行者123 更新时间:2023-11-30 08:11:54 28 4
gpt4 key购买 nike

我正在寻找如何检查已呈现并包含项目集的 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}
]
});

此组件将通过单击按钮显示在模态窗口中,因此我必须根据要修改的记录重新检查复选框组中的项目。

例如,当我第一次显示窗口时,我必须预先检查项目 123,第二次 - 245

所以真正的问题是:如何遍历复选框组项目并选中/取消选中复选框?

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

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

谢谢。


UPD

已找到答案。当我被允许接受我自己的答案时,问题将在 2 天内关闭,或者如果其他人回答正确则更早 =))

最佳答案

已找到解决方案。 Sencha 说:

setValue(Object value): Ext.form.CheckboxGroup

Sets the value(s) of all checkboxes in the group. The expected format is an Object of name-value pairs corresponding to the names of the checkboxes in the group. Each pair can have either a single or multiple values:

  • A single Boolean or String value will be passed to the setValue method of the checkbox with that name. See the rules in Ext.form.field.Checkbox.setValue for accepted values.
  • An Array of String values will be matched against the inputValue of checkboxes in the group with that name; those checkboxes whose inputValue exists in the array will be checked and others will be unchecked.

所以我只是将 name: "cbgroup" 属性添加到 checkbox 配置,然后我使用类似的构造

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

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

关于javascript - 检查 CheckboxGroup ExtJS 组件中的各种复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9079600/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com