This is a migrated thread and some comments may be shown as answers.

Clearing nodes from a treeview...

1 Answer 52 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Peter Ryckaert
Top achievements
Rank 1
Peter Ryckaert asked on 30 Jul 2010, 09:53 AM

 

var tree = $find(this.treeviewId); 
var count = tree.get_nodes().get_count(); 
for (var i = 0; i < count; i++) { 
   tree.get_nodes().remove(tree.get_nodes().getNode(0));
}

This is not working when nodes has some children... Wouldn't be simpler if there was a clear() function ?

--> Is this the Telerik HTML Editor ??? I can't format the code there, he's adding always linebreaks

1 Answer, 1 is accepted

Sort by
0
Peter Ryckaert
Top achievements
Rank 1
answered on 30 Jul 2010, 10:03 AM

This should do the trick... But Javascript doesn't like recursion...

TreeRemove: function(nodes) {
    var count = nodes.get_count();
    for (var i = 0; i < count; i++) {
        this.TreeRemove(nodes.getNode(0).get_nodes());
        nodes.remove(nodes.getNode(0));
    }
},
LoadGrid: function(categoryId, parentId) {
    ShowLoading(this.treeviewId);
    this.currentCategory = categoryId;
    services = new GridDataServices();
    if (parentId == 0) {
        var tree = $find(this.treeviewId);
        this.TreeRemove(tree.get_nodes());
    }
    var self = this;
    var LoadGridResult = function(result) { self.LoadGridResult(parentId, result); }
    services.KeywordsGetNodes(
                categoryId, parentId,
                LoadGridResult, null, null);
},
Tags
TreeView
Asked by
Peter Ryckaert
Top achievements
Rank 1
Answers by
Peter Ryckaert
Top achievements
Rank 1
Share this question
or