bug in current position in move_node (move_node data.rslt.cp)

332 views
Skip to first unread message

Daco Harkes

unread,
Jul 1, 2010, 10:39:40 AM7/1/10
to jsTree
Hey there,

First of all I want to say I really like jsTree. Keep up the good
work!


I have found a bug in the move_node. The data.rslt contains a cp
(current position).
The current position doesn't count in that the node is removed from
the old parent.

Example:
- a (position 1)
- b (position 2)
- c (position 3)
move c between a and b: cp=1
move a between b and c: cp=2

In both cases the moved node ends up on the 2nd place, but the cp is
different.


I also have some general feedback:
It would also really help if there was more documentation. It was
through google and through this google group I found out how to get
things to work.
Longer variable names help too. if np was named newParent i would have
found it 5x as fast probably.

One more simple thing for simplification:
I use this now: $('#menu').bind("move_node.jstree", function (event,
data) { ... }
For onclicks i use deligate: $("#menu").delegate("a","click",
function(e) { ... }


Greetings,
Daco

vakata

unread,
Jul 2, 2010, 3:46:01 AM7/2/10
to jsTree
Hi,

I will see about cp ... actually the PHP class deals with that on the
server side, but you are possibly right - I will see what I can do.

As for the docs - I am working on them for 1.0 final, but I am afraid
I won't be changing any of the names - maybe it was an error (in the
move callback, but quite a few people use them already, however you
can make your own custom one-function plugin to fix that - just
overwrite the get_move function, in your function call the old one,
get the result, append the new properties and return the object.

As for the clicks - if you need to intercept them - simply use the UI
plugin and the "select_node.jstree" event.

Cheers,
Ivan

Daco Harkes

unread,
Jul 2, 2010, 8:58:09 AM7/2/10
to jsTree
Hey,

Thanks for the quick response.

In your PHP/database you also use left, right and level fields.
However not all trees in databases save that information. (My tree
does just a parent id and a position(e.g. x-th child).)

I found a workaround for the moment:
Use data.rslt.o.index() instead of data.rslt.cp.
Its not data directly from the tree, so its less safe, but it does the
trick.

Drop me a note on cp once you figured it out.

Thx for all the work!
Daco

Jon

unread,
May 30, 2011, 11:26:58 AM5/30/11
to jst...@googlegroups.com
I am observing the same issue with the move_node.  This is reproducible on the PHP + mySQL demo page.

Using the example Daco provided:

- a (position 1)
- b (position 2)
- c (position 3)
move c between a and b
move a between b and c

Notice the order of the nodes now reads "c, a, b"
Now refresh the page using your browser so that the data is pulled from the database.
Notice the order of the nodes is now "c, b, a"

The correct position is critical to our implementation.

Ivan Bozhanov

unread,
Jul 11, 2011, 7:16:28 PM7/11/11
to jst...@googlegroups.com
It is fixed in 1.0, but 1.0 is not public yet, so in the mean time - use the fix mentioned above (using the .index() method on data.rslt.o)

Kindest regards,
ivan
Reply all
Reply to author
Forward
0 new messages