问题描述:在form中设置checkbox的值设置不进去,checkbox分为functionIds和modules,分别给他们指定了inputValue,详细问题请看下面的代码和带有"**"的注释,该代码可以运行,有一个测试的tabr。谢谢
[code="javascript"]
Ext.onReady(function() { // form的元素
var mItems = [{
colspan : 2,
xtype : 'panel',
layout : 'table',
items : [{
xtype : 'numberfield',
name : 'id',
hidden : true
}, {
xtype : 'numberfield',
name : 'unitCodePcId',
hidden : true
}, {
xtype : 'label',
text : '角色名称:'
}, {
xtype : 'textfield',
width : 200,
name : 'roleName'
}, {
xtype : 'label',
text : '系统最高用户:'
}, {
xtype : 'label',
text : '是'
}, {
// 这个值就可以设置进来
xtype : 'radio',
name : "isTOPUser",
inputValue : true
}, {
xtype : 'label',
text : '否'
}, {
xtype : 'radio',
name : "isTOPUser",
inputValue : false
}]
}];
// 模块的数据,真是业务是从数据库查询得来
var modules = [{
id : 1,
moduleCode : 'userManager',
moduleName : '用户管理',// 一级模块
functions : [],
modules : [{
id : 4,
moduleCode : 'userRegister',
moduleName : '用户注册',
functions : [{
id : 1,
typ : 0
}]
}, {
id : 7,
moduleCode : 'unitRegister',
moduleName : '单位注册',
functions : [{
id : 2,
typ : 0
}, {
id : 5,
typ : 1
}]
}]
}];
var functionText = ['录入', '查询', '打印'];
// 循环添加checkbox
Ext.each(modules, function(module) {
var m1Label = {
xtype : 'label',
text : module.moduleName,
style : "font-weight:bold;",
colspan : 2
};
mItems.push(m1Label);
Ext.each(module.modules, function(module2) {
var mCheckBox = {
xtype : 'panel',
layout : 'form',
items : [{
xtype : 'checkbox',
name : 'moduleIds',
fieldLabel : module2.moduleName,
// inputValue是module的id
inputValue : module2.id
}]
};
mItems.push(mCheckBox);
var fItems = [];
Ext.each(module2.functions, function(f) {
var itemCheckBox = {
xtype : 'panel',
layout : 'form',
items : [{
xtype : 'checkbox',
name : 'functionIds',
fieldLabel : functionText[f.type],
// inputValue是function的id
inputValue : f.id
}]
};
fItems.push(itemCheckBox);
});
var fPanel = {
xtype : 'panel',
layout : 'table',
items : fItems
}
mItems.push(fPanel);
});
});
var form = new Ext.FormPanel({
width : '100%',
height : 500,
layout : "table",
autoScroll : true,
autoWidth : false,
autoHeight : false,
frame : true,
renderTo : Ext.getBody(),
defaults : {
height : 22,
width : '100%',
labelAlign : 'right'
},
layoutConfig : {
tableAttrs : {
cellspacing : 4,
cellpadding : 4,
border : 0,
width : '100%'
},
columns : 2
},
items : mItems,
tbar : [{
text : '测试设置form checkbox的值',
handler : function() {
var value = {
id : 1,
roleName : '测试',
unitCodePcId : 22,
isTOPUser : true,
// name为"functionIds" checkbox的值
functionIds : [1, 2, 5],
// name为"modules" checkbox的值
modules : [4, 7]
};
// *****在这里如果勾选了checkbox,formgetValues就可以得到checkbox的值
var t = form.getForm().getValues();
// *****但是这里setValues的时候不能把值设置到form中,查看了setValues()方法的源码也没看出个头绪
form.getForm().setValues(value);
t = form.getForm().getValues();
var tt;
}
}]
});
});
[/code]