Home > Web Front-end > JS Tutorial > Extjs optimization (1) Delete redundant code to improve running speed_extjs

Extjs optimization (1) Delete redundant code to improve running speed_extjs

WBOY
Release: 2016-05-16 17:37:06
Original
1281 people have browsed it

Extjs itself is a slow-loading JS framework, which requires more optimization by programmers. I have mentioned before Optimization of JS packaging
This time I will write about how to reduce redundant code, which is also an improvement. Running speed, including 1. Universal deletion code 2. Universal submission form 3. Universal initialization of Gird This time only write and delete code optimization
Post the code first

Copy the code The code is as follows:

/**
* Get 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(a) {
Ext .Msg.confirm("Message confirmation", "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", "The record was successfully deleted!");
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", "An operation error occurred, please contact the administrator! ");
}
});
}
});
}
/**
* Gird batch deletion operation
*/
function $delGridRs(a) {
var b = $getGdSelectedIds(a.grid, a.idName);
if (b.length == 0) {
Ext.ux.Toast.msg("Operation information", "Please select to delete record! ");
return;
}
var c = {
url: a.url,
ids: b,
grid: a.grid
} ;
$postDel(c);
}

The optimization result of a single deletion code was changed from the original 24 lines of code to 5 lines of code, and the code looks better.
Copy code The code is as follows:

var a = Ext.getCmp("PlanBookAllGrid");
//Single delete
$postDel({
url: __ctxPath "/traincost/multiDelPlanBook.action",
ids: b,
grid: a
});

The same goes for batch deletion
Copy code The code is as follows:

$delGridRs ({
url: __ctxPath "/traincost/multiDelPlanBook.action",
grid:c.gridPanel,
idName:'mainid'
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template