TreeExpanded/Collapsed Listener

Hi there,

for my nodes I have a TreeExpanderButton which works fine. Now I would like to add a TreeExpander/Collapsed Listener and obtain a reference to the key of the node that I just clicked on. How do I do that?

Here’s what I would like a Listener to look like:

      function(e) {
        // Some code I can't figure out that gets me node_key
        console.log("you just expanded node " + node_key);

I want something similar to this code sample on this page, but it appears that “part” refers to the expander button, not to the node.

<pre -="" id="diagrams" ="" style="border: 1px solid rgb204, 204, 204; padding: 0.5em; color: rgb51, 51, 51; : rgb248, 248, 255; line-height: normal;">  diagram.addDiagramListener(<span ="" style="color: rgb196, 26, 22;">"ObjectSingleClicked"</span>,
      <span ="keyword" style="color: rgb170, 13, 145;">function</span>(e) {
        <span ="keyword" style="color: rgb170, 13, 145;">var</span> part = e.subject.part;
        <span ="keyword" style="color: rgb170, 13, 145;">if</span> (!(part <span ="keyword" style="color: rgb170, 13, 145;">instanceof</span> go.Link)) showMessage(<span ="" style="color: rgb196, 26, 22;">"Clicked on "</span> +;

Thank you very much!

Unlike the “ObjectSingleClicked” DiagramEvent where there is just a single GraphObject that was clicked (from which you can get the Part that it was in), the “TreeExpanded” DiagramEvent.subject is the collection of Nodes that were expanded. It’s not just a single Node, although I suppose in your case, going through the TreeExpanderButton, it always would be a single Node.

So: e.subject.first() should be the Node that you care about.

That works great! Thanks very much!