It seems that javascript variable types can also be divided into value types and reference types. In assignment operations, value types are independent of each other. A reference type, just a pointer, they all point to the same object.
Why do you say that?
I know this from jeasyUI’s Treegrid batch deletion of multiple rows.
To delete multiple rows in a Treegrid batch, get the selected rows first:
var rows = _grid.treegrid(‘getSelections’); \
And then iterate over it and delete it
for (var i = 0; i < rows.length; i++) { var id = rows[i].id; _grid.treegrid(‘remove’, id); } \
There’s always some left over.
The reason for this is that rows is a reference type, it refers to those rows, the rows are deleted, the rows.length is reduced by 1, and the loop ends very quickly. This is the same as before in C#, traversing and deleting records in the DataTable.
Select * from ‘rows’ where the id is stored in an array (array is the value type), then iterate over the array and delete:
//var _grid = $("treegridDemo");
var rows = _grid.treegrid('getSelections');
var ids = new Array(a);for (var i = 0; i < rows.length; i++) {
ids[i] = rows[i].id;
}
for (var i = 0; i < ids.length; i++) {
_grid.treegrid('remove', ids[i]);
}
_grid.treegrid('reloadFooter');
Copy the code
\