Topic: how to reference a newly added node

Hi,

Is there a way to select a newly added node?  I need a way to do this because I wish to automatically call rename() after adding each node.

After reading this thread http://mifjs.net/forum/topic/77/, I figured that perhaps I can do something like tree.select(tree.ids[uid]), but my browser tells me that "tree.ids" has no properties.

Regards,

[ simon.cpu ]

Re: how to reference a newly added node

LOLz... I noticed that I kept on replying to my own threads.  Anyway, I just overrode the add() method:

Mif.Tree.implement({
    add: function(node, current, where){
        if(!(node instanceof Mif.Tree.Node)){
            node=new Mif.Tree.Node({
                parentNode: null,
                tree: this
            }, node);
        };
        node.inject(current, where, Mif.Tree.Draw.node(node));
        this.fireEvent('add', [node, current, where]);
        node.rename();

        return this;
    }
});

I hope this solutions helps other people too! smile

Last edited by simoncpu (2009-10-19 13:57:40)

Re: how to reference a newly added node

Blah.  Here's an easier solution:

var node = tree.getSelected();
var new_node =  new Mif.Tree.Node({
    parentNode  : node,
    tree        : tree
    }, {property: {name: foobar.getTmpName(node),}
});
tree.add(new_node, node, 'inside');
new_node.rename();

lol

Last edited by simoncpu (2009-10-19 14:04:50)