EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: gregma on September 02, 2014, 02:45:40 AM



Title: how to select a specific node after a tree load
Post by: gregma on September 02, 2014, 02:45:40 AM
hi
  I am using the tree control. the following codes does not select the node I want. I guess this is due to the async nature of the tree control: when 'find' method is executed, the tree's data may not arrive yet. I tried other ways such as placing the 'select' method in the formatter function, but none of them seems to work. Do you guys know how to do it? Thanks in advance.

    var g_node_id = 11;
    $('#tt').tree
    ({
      url: "<c:url value='/student/classlist'/>",
      method:'get',
      ...
    });

    var node = $('#tt').tree('find', g_node_id);
    if (node)
      $('#tt').tree('select', node.target);


Title: Re: how to select a specific node after a tree load
Post by: stworthy on September 02, 2014, 06:10:55 PM
Please try this:
Code:
$('#tt').tree({
url: "<c:url value='/student/classlist'/>",
method:'get',
onLoadSuccess:function(){
var node = $(this).tree('find', g_node_id);
if (node){
$(this).tree('select', node.target);
}
}
})


Title: Re: how to select a specific node after a tree load
Post by: gregma on September 02, 2014, 08:31:13 PM
Please try this:
Code:
$('#tt').tree({
url: "<c:url value='/student/classlist'/>",
method:'get',
onLoadSuccess:function(){
var node = $(this).tree('find', g_node_id);
if (node){
$(this).tree('select', node.target);
}
}
})

Wow, You are a great help! Thanks a lot!