处理extjs checkboxgroup上的更改事件
我对如何处理checkboxgroup中的更改感到非常困惑。 我想得到一个数组,它包含所有复选框的新值。 最后一个数组将具有chekbox的id及其相应的值(无论是否选中) 我将此复选框组设置为动态处理extjs checkboxgroup上的更改事件,extjs,Extjs,我对如何处理checkboxgroup中的更改感到非常困惑。 我想得到一个数组,它包含所有复选框的新值。 最后一个数组将具有chekbox的id及其相应的值(无论是否选中) 我将此复选框组设置为动态 var checkboxconfigs = []; checkboxconfigs.push({ //pushing into array id:record.data.SubTickets[z].Id, boxLabel:record.d
var checkboxconfigs = [];
checkboxconfigs.push({ //pushing into array
id:record.data.SubTickets[z].Id,
boxLabel:record.data.SubTickets[z].Name,
status:record.data.SubTickets[z].Status
});
xtype: 'checkboxgroup',
fieldLabel: 'Checklist',
columns: 1,
vertical: true,
listeners: {
change: function(field, newValue, oldValue, eOpts)
{
}
},
items: checkboxconfigs
接下来我需要得到一个包含所有新值及其各自id的数组。
可能类似于键值对数组,因此我可以将此数组传递给函数。
在创建“我想调用函数”之后,如何在此处创建此数组。可能编码不完美,但您可以将其用作示例
myCheckboxGroup.on({
change: function(checkboxGroup, newValue) {
var formattedValues = [];
// myGroup is your checkboxes `name` property
newValue = newValue.myGroup.length === 0 ? [newValue.myGroup] : newValue.myGroup;
checkboxGroup.items.each(function(checkbox){
var checkboxValue = checkbox.inputValue,
foramttedValue = {};
foramttedValue[checkboxValue] = newValue.indexOf(checkboxValue) !== -1 ? 'on' : 'off';
formattedValues.push(foramttedValue);
});
console.log(formattedValues);
}
});
JSON中的格式化值如下所示
[{"field1":"off"},{"field2":"on"},{"field3":"off"},{"field4":"on"},{"field5":"off"}]
我在复选框上设置了
name
和inputValue
,这就行了。@Alexander谢谢!但我关心的是另一件事。我想创建一个数组,例如:[{'123':'on'},{'456':''},这些是数组的新值。此外,我需要将数组传递给函数,但不知道从何处调用函数。我希望在更改事件后传递函数。在更改事件中,将创建数组,然后在更改后,我希望调用函数。感谢这对我的帮助!已接受,不能放弃,不允许我这样做。