/** * 循环创建带label的CheckBox集合 */require(["dijit/form/CheckBox","dojo/dom-construct","dojo/domReady!"], function(CheckBox,domConstruct){// 创建数据var data_list = [ { col1: "normal", col2: false, col4: 29.91}, { col1: "impo
/** * 循环创建带label的CheckBox集合 */ require(["dijit/form/CheckBox","dojo/dom-construct","dojo/domReady!"], function(CheckBox,domConstruct){ // 创建数据 var data_list = [ { col1: "normal", col2: false, col4: 29.91}, { col1: "important", col2: false, col4: 9.33}, { col1: "very", col2: false, col4: 19.34} ]; for( i = 0; i < data_list.length; i++ ) { var item = data_list[i]; // CheckBox var boxOne = new CheckBox({ name: "types" }); // 放到指定html标签 boxOne.placeAt('childDocLib'); // 根据数据的值设置CheckBox title、value属性 boxOne.set('title',item.col4); boxOne.set('value',item.col4+''); // 不加''会取不到值 if( i == 2 ) { // 选中 boxOne.set('checked',true); }else { boxOne.set('checked',false); } // 因为checkbox自带label不起作用,又想在checkbox后显示文字,所以通过这种方法添加label标签实现 childDocLib.appendChild(domConstruct.create("label", {innerHTML: item.col4})); } });
<table> <tr> <td id="childDocLib"></td> </tr> </table>