When we use Extjs to develop a system, Extjs obtains data from the background through json and sends data to the server through Post when saving the data: [javascript] Ext. ajax. request ({url: & quot;/application/controller/field/AddHeaderGroup. action & quot ;,...
When we use Extjs to develop a system, Extjs obtains data from the background through json and sends data to the server through Post when saving the data:
[Javascript]
Ext. Ajax. request ({
Url: "/application/controller/field/AddHeaderGroup. action ",
Method: 'post ',
Params :{
DisplayName: nodeText,
QueryId: queryId
},
Success: function (response, opts ){
NewNode. set ("id", response. responseText. replace (/'/g ,""));
// Console. log (newNode. get ('id '));
ParentNode. appendChild (newNode );
}
});
Sometimes you need to click "save" after editing a complete grid to save the content of the entire grid at a time. Extjs can get changed and deleted content through the getModifiedRecords and getRemovedRecords methods of store. This usually uses javascript Arrays: first, push a row of data to the array, then push the array of a row of data to another array, and send it to the server. The server restores the data content through string parsing.
There is a deficiency in this process: if there is "," in the string data in the array, the server often cannot get the correct result when parsing the data-the server can only use the string split (", ") function to split the string.
So how can we solve this problem?
Extjs provides Array encoding: Ext. encode (Array) to solve this problem. When an array is pushed to another array, arr1.push (Ext. encode (arr2) is used to push the encoded data to another array (multi-layer nested Arrays can be used ). Then, when the server parses each array encoded with Ext. encode (), JSONArray. fromObject (groupList) is used to restore the string to a JSONArray. Of course, each JSONArray. fromObject corresponds to an Ext. encode (). This perfectly solves the problem caused by "," in the string when Extjs saves data in batches.