Clearing nodes from a treeview...

2 posts, 0 answers
  1. Peter Ryckaert
    Peter Ryckaert avatar
    16 posts
    Member since:
    Jul 2006

    Posted 30 Jul 2010 Link to this post

     

    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
  2. Peter Ryckaert
    Peter Ryckaert avatar
    16 posts
    Member since:
    Jul 2006

    Posted 30 Jul 2010 Link to this post

    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);
    },
Back to Top