1. #1
    Sencha User
    Join Date
    Sep 2007
    Posts
    35
    Vote Rating
    1
    DannyR is on a distinguished road

      1  

    Default How to delete a node off the tree?

    How to delete a node off the tree?


    This shouldn't be that hard, should it? I need to search through the store to find nodes that meet a certain criteria, and simply delete them (be they leaves or branches)?

    Here's what I've got:

    Code:
    var store = tree.getStore();store.doOnLoad(function(store) {
        var root = Ext.valueFrom(null, tree.getRootNode());
        root.cascadeBy(function(node) { 
            if (node.get("archived") == true) {
                store.getById(node.internalId).remove();
            }
        });
    });
    It's throwing a "childNodes[i] is undefined" error: childNodes[i].cascadeBy(fn, scope, args); [ext-all-dev.js (line 56625)]

    Since it's throwing that inside a recursion loop, it would seem to indicate that it doesn't know to not follow that branch when its ancestor has been deleted. But that's only a guess at this point.

    Been beating my head against the wall for far too long on this one. Any help would be greatly appreciated.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You need to use the removeChild method on the parent node
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member sonata82's Avatar
    Join Date
    Aug 2011
    Posts
    19
    Vote Rating
    9
    sonata82 will become famous soon enough

      0  

    Default


    In the callback of cascadeBy, you shouldn't alter the structure of the tree.

    To delete a number of childnodes you could use the following structure:

    Code:
    var i, node,
        nodesToDelete = [];
    
    
    this.getEntitiesStore().getRootNode().cascadeBy(function (node) {
        if (insert your requirement here) {
            nodesToDelete.push(node);
        }
    }, this);
    
    
    for (i = 0; (node = nodesToDelete[i]); i++) {
        node.parentNode.removeChild(node);
    }

Thread Participants: 2