Question

I am looking at the dynatree documentation, and it shows that the onClick callback function is passed two parameters: node & event. What exactly are these parameters? I would assume that the "node" parameter is of type DynaTreeNode.

What I am looking for is to get a reference to the element associated with the node when the onClick callback is called for an <a> element. I know that in that case, node.data.href will equal the href of the <a> element and node.getEventTargetType(event) will return "title". The <a> element will have the class "dynatree-title". I am actually looking for a reference to the <span> tag that immediately precedes the <a> element. It will have the class "dynatree-expander". If I can get a reference to the <a> element, I can use the jQuery .prev() method to get the <span>.

I need to perform conditional login in the onClick callback when it is called for an <a> element that is preceded by a <span class="dynatree-expander"> element.

EDIT:

Because of the following posts, I have been focusing on the "node" parameter. They show it might have properties that are not listed in the documentation. However, I believe the "event" parameter might be the same as the "event" parameter to a jQuery on-click handler. Therefore, I should be using event.target. I will experiment and see if that works.

Here are the posts showing the "node" parameter to have undocumented properties:

  1. This post shows node.span for onActivate.
  2. This post shows node.span for onPostInit.
  3. This post shows node.span, node.ul, and node.li for onRender.

But then I saw this post which showed the use of event.target.

Was it helpful?

Solution

The "node" parameter is definitely of the type DynaTreeNode listed in the dynatree documentation. I looked through its properties and all the properties documented for DynaTreeNode are there. It's prototype is empty though; The properties are all directly on the object.

There are a few properties on "node" that are not listed in the documentation. Some of the property names begin with underscores, so they definitely should not be used, but others do not. The list of undocumented properties does include "ul", "li", and "span". Others of note are "childList", "parent" and "tree". Although "tree" is not listed for the DynaTreeNode type, several examples in the documentation show its use.

The "node.span" element is a <span> that surrounds both the <span> for the expander icon and the <a> that contains the title. The "node.li" element is the <li> that surrounds the <span> referenced by "node.span". I would have thought "node.ul" would reference the surrounding <ul> element, but it was always null for me.

Some of the functions on the "node" parameter that are not documented are "append", "collapseSiblings", "fromDict", and "removeChild".

The "event" parameter does appear to be a jQuery event parameter, so event.target works just fine to get the element that was clicked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top