Extjs optimization (1) Delete redundant code to improve the running speed _ extjs

Source: Internet
Author: User
Extjs itself is a slow loading JS framework. How to reduce redundant code written this time also improves the running speed. If you are interested, refer to the following, I hope it will help you to understand that Extjs itself is a JS framework with slow loading. This requires many programmers to optimize it. I have mentioned the JS packaging optimization before.
How to reduce redundant code writing this time is also to improve the running speed, including 1. Delete Code generic 2. Submit Form generic 3. initialize Gird generic this write-only delete code optimization
First paste the code

The Code is as follows:


/**
* Obtain the selected record of a GridPanel
*/
Function $ getGdSelectedIds (grid, idName ){
Var selRs = grid. getSelectionModel (). getSelections ();
Var ids = Array ();
For (var I = 0; I <selRs. length; I ++ ){
Ids. push (eval ("selRs [I]. data." + idName ));
}
Return ids;
}
/**
* Delete
*/
Function $ postDel (){
Ext. Msg. confirm ("confirm information", "Are you sure you want to delete the selected record? ",
Function (B ){
If (B = "yes "){
Ext. getBody (). mask ("deleting, please wait ");
Ext. Ajax. request ({
Url: a. url,
Params :{
Ids: a. ids
},
Timeout: 100000000, // default 30000 milliseconds
Method: "POST ",
Success: function (c, d ){
Ext. getBody (). unmask ();
Ext. ux. Toast. msg ("operation information", "deleted successfully! ");
If (a. callback ){
A. callback. call (this );
Return;
}
If (a. grid ){
A. grid. getStore (). reload ();
}
},
Failure: function (c, d ){
Ext. getBody (). unmask ();
Ext. ux. Toast. msg ("operation information", "Operation error. Please contact the administrator! ");
}
});
}
});
}
/**
* Batch Delete Gird operations
*/
Function $ delGridRs (){
Var B = $ getGdSelectedIds (a. grid, a. idName );
If (B. length = 0 ){
Ext. ux. Toast. msg ("operation information", "select the record to delete! ");
Return;
}
Var c = {
Url: a. url,
Ids: B,
Grid: a. grid
};
$ PostDel (c );
}


The optimization result of a single Delete Code is changed from the original 24 lines of code to 5 lines of code, and the code looks better.

The Code is as follows:


Var a = Ext. getCmp ("PlanBookAllGrid ");
// Delete a single object
$ PostDel ({
Url: _ ctxPath + "/traincost/multiDelPlanBook. action ",
Ids: B,
Grid:
});


The same is true for batch deletion.

The Code is as follows:


$ DelGridRs ({
Url: _ ctxPath + "/traincost/multiDelPlanBook. action ",
Grid: c. gridPanel,
IdName: 'mainid'
});

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.