请参阅下面的示例。控制台使用" undefined"来记录数组。从下拉列表中检查项目时的对象。获取一系列已检查项目的正确方法是什么? http://jsfiddle.net/4L3sksmt/4/
require(['dojox/form/CheckedMultiSelect'],function(CheckedMultiSelect){
var groupCheckedMultiSelect = new CheckedMultiSelect ({
id: "groupChkMultiSelect",
dropDown: true,
multiple: true,
label: "Group",
onChange: function(evt){
console.log(evt);//output = undefined
}
}, 'GroupDiv');
groupCheckedMultiSelect.addOption({'label':'One'});
groupCheckedMultiSelect.addOption({'label':'Two'});
groupCheckedMultiSelect.addOption({'label':'Three'});
groupCheckedMultiSelect.addOption({'label':'Four'});
groupCheckedMultiSelect.addOption({'label':'Five'});
groupCheckedMultiSelect.startup();
});

答案 0 :(得分:2)
返回undefined
值,因为您没有设置选项的值。选项的正确格式为{ label : 'One', value: 1 }
。下面的代码现在应该正常工作。
require(['dojox/form/CheckedMultiSelect'],function(CheckedMultiSelect){
var groupCheckedMultiSelect = new CheckedMultiSelect ({
id: "groupChkMultiSelect",
dropDown: true,
multiple: true,
label: "Group",
onChange: function(evt){
console.log(evt);//output = undefined
}
}, 'GroupDiv');
groupCheckedMultiSelect.addOption({'label':'One', value: 1});
groupCheckedMultiSelect.addOption({'label':'Two', value: 2});
groupCheckedMultiSelect.addOption({'label':'Three', value: 3});
groupCheckedMultiSelect.addOption({'label':'Four', value: 4});
groupCheckedMultiSelect.addOption({'label':'Five', value: 5});
groupCheckedMultiSelect.startup();
});