0

I'm following along with the VirtualTree demo and can't seem to find a way to get at the parents of a selection:

tree.getSelection().addListener("change", function(e){
    var selection = tree.getSelection();
    console.log(selection.getItem(0).getName()); // works just fine to get the name
}

I'm trying to get at the properties "Grandparent" and "Parent" from this JSON store:

  {
      "name": "root",
      "children": [
        {
          "name": "Grandparent",
          "children": [
            {
              "name": "Parent",
              "children": [
                {
                   "name": "Name of my Selected Item",

I've tried this:

tree.getModel().getChildren().getItem(0)

but getting at value X for getItem(X) is not straightforward either.

I'd appreciate any help you can provide on this. Thanks!

Jonathan
  • 894
  • 2
  • 9
  • 20

1 Answers1

1

As the tree data model does not have any parent reference by default. There is no easy way to get achieve that. Still, you have two choices.

  1. You can use your own tree classes as model and implement the parent reference yourself. This can be done by using the delegate of the marshaler [1]. Just make sure you don't activate the bubble events for the parent reference because that leads to an dead lock.

  2. You can implement an search algorithm to get the parent. If you don't need that reference very often and your data is not too big, thats also a way you could take.

[1] http://demo.qooxdoo.org/current/apiviewer/#qx.data.marshal.IMarshalerDelegate

Martin Wittemann
  • 2,109
  • 1
  • 12
  • 14
  • Thanks @Martin Wittemann! Method one is a little above my programming expertise. Method two would definitely work since my dataset is rather small. I may just include the information that I was going to put in the parent in each of the children--it's a little more work that way. Having a function to access the parents may be a nice future enhancement of qooxdoo :-) Thanks again! – Jonathan May 24 '12 at 10:41