[英]How to dynamically change checkbox value in extjs app?
我有一个面板,它将呈现动态复选框。 在事件侦听器之后,需要根据服务器返回的JSON中的true / false值动态更新复选框。 该应用程序是在Extjs 4.2版本中开发的。 我检查了渲染复选框后,它们是否已加载数据,但立即被清除。
要动态生成复选框...。
Ext.Ajax.request({
url: 'http://soup.nielsen.com/test/test5.php',
method: 'POST',
success: function(result, request) {
var json = result.responseText;
var temp = JSON.parse(json);
for(var i=0;i<Object.keys(temp[newValue]).length;i++){
menuArray.push({
xtype: 'checkboxfield',
boxLabel: (temp[newValue][i]).split("_").join(" "),
name: temp[newValue][i],
id:temp[newValue][i],
inputValue: 'true',
uncheckedValue: 'false',
formBind: false
});
}
checkboxGroup = new Ext.form.CheckboxGroup({
xtype: 'checkboxgroup',
fieldLabel: '',
id:'moduleCheckboxGroup',
columns: 1,
items: menuArray
});
permissionPanel.removeAll();
permissionPanel.add(checkboxGroup);
},failure: function(result, request) {
Ext.Msg.alert('Error', 'An Error occured...');
} });
要向复选框加载数据...
if(grid.getSelectionModel().hasSelection()){
var userID = grid.getSelectionModel().getSelection()[0].data.ID;
var userName = grid.getSelectionModel().getSelection()[0].data.FULL_USER_NAME;
var userGroup = grid.getSelectionModel().getSelection()[0].data.USER_GROUP;
//Creating Dynamic Checkboxes to load User module permissions
var permissionPanel = Ext.getCmp('permissionsPanel');
permissionPanel.show();
var checkboxGroup;
var menuArray = [];
var names = [];
var fieldset;
// Loading a selected user data into user form
var form = Ext.getCmp('userForm').getForm();
Ext.Ajax.request({
url: 'http://soup.nielsen.com/test/Get_All_User_Info_byID2.php',
method: 'POST',
params: {num:userID},
success: function(result, request) {
var json = result.responseText;
var temp = JSON.parse(json);
//form.reset();
Ext.getCmp('allUsersListPanel').hide();
Ext.getCmp('userPanel').show();
Ext.getCmp('userGroup').setValue(temp.USERINFO.USER_GROUP);
form.setValues(temp.USERINFO);
perForm.setValues(temp.USERINFO);
},
failure: function(result, request) {
Ext.Msg.alert('Error', 'An Error occured...');
}
}); } else {Ext.Msg.alert('Message','Please select a user');}
1)您不需要使用inputValue:'true',uncheckedValue:'false'configs:value或checked就足够了
2)您不需要使用id,只是使用名称实际上从不使用id这是一个坏习惯。 如果需要像查询一样的ID的查询,建议使用itemId
menuArray.push({
xtype: 'checkboxfield',
boxLabel: (temp[newValue][i]).split("_").join(" "),
name: temp[newValue][i],
value : false, // or checked : false
formBind: false
});
3)您的json对象属性名称应与表单字段名称匹配
form.setValues(temp.USERINFO);
perForm.setValues(temp.USERINFO)
换句话说,temp.USERINFO对象应具有名称为temp [newValue] [i]的属性(当然是value)
总结:
以表格形式设置“名称”; 如果没有,则应该setValue()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.