Move all the children of a node to another node

154 views
Skip to first unread message

nc3b

unread,
Jun 28, 2010, 3:59:49 AM6/28/10
to jsTree
Hello.

What is the best way to move all the children of a node to another
node ? When the user removes a parent node, I want all the children to
move to another 'default' node. I couldn't find any info on this,
sorry if it's trivial / already been asked.

Thank you for your time :-)

vakata

unread,
Jun 28, 2010, 4:44:31 AM6/28/10
to jsTree
Hi,

I have not thoroughly tested, but you can do this:

.bind("remove.jstree", function (e, data) {
data.rslt.obj.find("> ul > li").each(function () {
data.inst.move_node(this, "#rhtml_4", "last");
});
// possibly sync to DB here
});

If this does not work - there are other approaches - just tell me.

Cheers,
Ivan

nc3b

unread,
Jun 28, 2010, 5:17:39 AM6/28/10
to jsTree
Thank you, this works great. Unfortunately this also fires the
'move_node' event, which I currently use to update the database when
the user drags a node to another parent. Is there any way to prevent
this ?

nc3b

unread,
Jun 28, 2010, 5:31:01 AM6/28/10
to jsTree
I managed to prevent that event from firing like so

$("#the-tree").unbind("move_node.jstree", on_move_node);
data.rslt.obj.find("> ul > li").each(function () {
data.inst.move_node(this, "#default_parent", "last");
});
$("#the-tree").bind("move_node.jstree", on_move_node);

Please let me now if there is a better way to achieve this.

mike....@gmail.com

unread,
Jul 26, 2017, 9:32:28 AM7/26/17
to jsTree
How we would do it if instead of selected node we had a node id?
Reply all
Reply to author
Forward
0 new messages