Dojo关于dijit/form/CheckBox序列化的疑问?请大侠指教

使用dijit/form/CheckBox发现序列化的时候将他的值序列化为Array。不知道为啥?请大侠指教!

HTML源码如下

<!DOCTYPE html>
<head>
<Meta http-equiv="X-UA-Compatible" content="IE=7" />
<title></title>
<link href="dijit/themes/claro/claro.css" rel="stylesheet" type="text/css" />
<script src="dojo/dojo.js" data-dojo-config="async: true,parSEOnLoad: true"></script>
<script type="text/javascript">
require(["dojo/ready","dijit/Dialog","dijit/form/Button","dijit/form/CheckBox"],function(ready){

ready(function(){

});
});
</script>
</head>
<body class="claro">
<div data-dojo-type="dijit/Dialog" data-dojo-id="myFormDialog" title="Form Dialog" execute="alert('submitted w/args:\n' + dojo.toJson(arguments[0],true));">
<div class="dijitDialogPaneContentArea">
<table>
<tr>
<td><label for="EState">CheckBox</label></td>
<td><input id="EState" name="EState" data-dojo-id="frm_state" data-dojo-type="dijit/form/CheckBox" data-dojo-props="value:true" /></td>
</tr>
<tr>
<td><label for="EState1">CheckBox</label></td>
<td><input id="EState1" name="EState" data-dojo-id="frm_state" data-dojo-type="dijit/form/CheckBox" data-dojo-props="value:true" /></td>
</tr>
</table>
</div>

<div class="dijitDialogPaneActionBar">
<button data-dojo-type="dijit/form/Button" type="submit" data-dojo-props="onClick:function(){return myFormDialog.validate();}">
OK
</button>
<button data-dojo-type="dijit/form/Button" type="button" onClick="myFormDialog.hide()">
Cancel
</button>
</div>
</div>

<p>When pressing this button the dialog will popup:</p>
<button id="buttonThree" data-dojo-type="dijit/form/Button" type="button" onClick="myFormDialog.show();">
Show me!
</button>
</body>
</html>

经过调试发现

_DialogMixin.js中_onSubmit函数

this.onExecute();

this.execute(this.get('value')); //这就是我们dijit/Dialog 的execute属性。this.get('value')

在_FormMixin.js的_getValueAttr函数中,_getValueAttr源码如下:

var obj = { };
array.forEach(this._getDescendantFormWidgets(),function(widget){
var name = widget.name;
if(!name || widget.disabled){ return; }

// Single value widget (checkBox,radio,or plain <input> type widget)
var value = widget.get('value');

// Store widget's value(s) as a scalar,except for checkBoxes which are automatically arrays
if(typeof widget.checked == 'boolean'){
if(/Radio/.test(widget.declaredClass)){
// radio button
if(value !== false){
lang.setobject(name,value,obj);
}else{
// give radio widgets a default of null
value = lang.getobject(name,false,obj);
if(value === undefined){
lang.setobject(name,null,obj);
}
}
}else{
// checkBox/toggle button
var ary=lang.getobject(name,obj); //这就是代码
if(!ary){
ary=[];
lang.setobject(name,ary,obj);
}
if(value !== false){
ary.push(value);
}
}
}else{
var prev=lang.getobject(name,obj);
if(typeof prev != "undefined"){
if(lang.isArray(prev)){
prev.push(value);
}else{
lang.setobject(name,[prev,value],obj);
}
}else{
// unique name
lang.setobject(name,obj);
}
}
});

为啥作为数组使用?还是我使用方法有问题?

上面的HTML源码使用两个CheckBox,返回的值如源码所示只有当true才显示否则不显示

那么两个CheckBox只返回true而且还没有索引(否则不知道那个选true,那个选false)有啥用?

相关文章

我有一个网格,可以根据更大的树结构编辑小块数据.为了更容易...
我即将开始开发一款教育性的视频游戏.我已经决定以一种我可以...
我正在使用带有Grails2.3.9的Dojo1.9.DojoNumberTextBox小部...
1.引言鉴于个人需求的转变,本系列将记录自学arcgisapiforja...
我正在阅读使用dojo’sdeclare进行类创建的语法.描述令人困惑...
我的团队由更多的java人员和JavaScript经验丰富组成.我知道这...