Thursday 15 May 2014

extjs4 - How to dynamically change checkbox value in extjs app? -


I have a panel that will render the dynamic check box. After the event listener, the checkbox needs to be updated dynamically based on the right / wrong values ​​from the JSON that is returned from the server. The application has been developed in version 4.2. I have checked that after rendering the checkbox they are loading with the data, but it is being cleared immediately.

To generate a check box dynamically ....

  Ext.Ajax .request ({url: 'http://soup.nielsen.com/ Test / test5.php ', method:' post ', success: work (result, request) {var json = result.response textext; var temp = JSON for .Pars (JSN); (var i = 0; i & Lt; object (temp [newValue]) length; i ++) {menuArray.push ({xtype: 'checkbox field', boxelabel: (temp [newValue] [i ('' '), name: temp [newValue] [I], id: temp [newValue] [i], inputValue: 'true', uncheck value: 'false', formbind: wrong}};} checkbox group = new extension.checkbox group ({xtype: 'f Permalink .removeAll (); Add Permission Add (Checkbox Group);}, Failure: Function (Results, Requests, Requests, Requests) ) {Ext.Msg.alert ('Error', 'An error occurred ...')}}});   

To load the checkbox with data ...

  if (grid.getSelectionModel () .asis ()) {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; // User modules are creating dynamic checkboxes to load permissions var permissionPanel = Ext.getCmp ('Permissions Panel'); PermissionPanel.show (); Var checkbox group; Var menuArere = []; Var name = []; Var Field Set; // Load a selected user data form in the form form = Ext.getCmp ('userForm'). GetForm (); Ext.Ajax.request ({url: 'http://soup.nielsen.com/test/Get_All_User_Info_byID2.php', method: 'POST', parameter: {num: userID}, success: work (result, request) { Var json = result.responseText; var temp = JSON.parse (json); //form.reset (); Ext.getCmp ('allUsersListPanel') Hide (); Ext.getCmp ('userPanel'). Show () ; Et.getcmp ('User Group'). Set Value (temp.USERINFO.USER_GROUP); form.setValues ​​(temp.USERINFO); perForm.setValues ​​(temp.USERINFO);}, Failure: Function (result , Request) {Ext message.lert ('error', 'an error occurred ...')}}}); } Other {Ext.Msg.alert ('Message', 'Please Select User')}}    

1) You do not have to use the inputValue: 'true', unchecked value: 'false' configuration: value or check is sufficient

2) Not necessarily, just use the name. Really do not use the ID. This is a bad practice ItemId is re-modified if you query with query like ID Mr. requiring

  Menuarere. Push ({xtype: 'checkboxfield', boxLabel: (temp [newValue] [i]). Partition ("_") .join (""), name: temp [newValue] [i], value: false, // Or checked: wrong formbind: incorrect});   

3) Your Jason object property name must match the form field names

  form.setValues ​​(temp.USERINFO); In other words, temp.USERINFO object should have properties with name temporal [newValue] [i] (definitely worth)  

summary:

  • Delete the ID and configure the uncheck value from the checkbox
  • Make sure that your json object properties have the same name with the checkbox field

No comments:

Post a Comment