我有一个面板,它将呈现动态复选框。在事件侦听器之后,需要根据从服务器返回的 JSON 的真/假值动态更新复选框。该应用程序是在 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');}