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 '
});