easyui select the last selected node after reload

we urually reload easyui tree after edit some nodes, but after reload, the selected node before can not be re-selected. here’s a simple way:

<script type=”text/javascript”>
var selectednode=null;
$(function(){
$(‘#orgTree’).tree({
onClick: function(node){
selectednode = node;
},
onLoadSuccess: function(node, data){
$(‘#orgTree’).tree(‘collapseAll’);//collapse all but expand the root node
var root = $(‘#orgTree’).tree(‘getRoot’);
$(‘#orgTree’).tree(‘expand’,root.target);
if(selectednode != null){// if have seleted node before reload, select the node and expand //all parents.
var node = $(‘#orgTree’).tree(‘find’, selectednode.id);
if(node != null){
$(‘#orgTree’).tree(‘select’,node.target);
while(node != null){
$(‘#orgTree’).tree(‘expand’,node.target);
node = $(‘#orgTree’).tree(‘getParent’,node.target);
}
}
}
}
});

});

Snap1

This entry was posted in Java, javascript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s