ExtJs uses Array to send large amounts of data to the background

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.