ExtJS optimization (i) Remove redundant code to improve running speed _extjs

Source: Internet
Author: User
Extjs itself is a slow load of the JS framework, which requires a lot of programmers to optimize, previously said JS packaging optimization
This time to write write how to reduce redundant code, but also to improve the speed, including 1, delete code General 2, submit Form Universal 3, initialize gird generic this time write-only delete code optimization
Post the Code First
Copy Code code as follows:

/**
* Get a record of the Gridpanel selection
*/
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 (a) {
Ext.Msg.confirm ("Information confirmation", "Are you sure you want to delete the selected records?") ",
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 ("Action info", "Delete the record 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 Info", "Operation error, please contact admin!") ");
}
});
}
});
}
/**
* Gird Bulk Delete operation
*/
function $delGridRs (a) {
var B = $getGdSelectedIds (A.grid, a.idname);
if (B.length = = 0) {
Ext.ux.Toast.msg ("Action info", "Select the record you want to delete!") ");
Return
}
var C = {
Url:a.url,
IDS:B,
Grid:a.grid
};
$postDel (c);
}

Single Delete code optimization results from the original 24 lines of code modified to 5 lines of code to fix, the code looks more attractive.
Copy Code code as follows:

var a = ext.getcmp ("Planbookallgrid");
Single Delete
$postDel ({
URL: __ctxpath + "/traincost/multidelplanbook.action",
IDS:B,
Grid:a
});

The same is true for bulk deletions
Copy Code code 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.