0

我正在关注 VirtualTree 演示,似乎无法找到一种方法来获取选择的父母:

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

我正在尝试从此 JSON 存储中获取属性“祖父母”和“父母”:

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

我试过这个:

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

但是获取 getItem(X) 的值 X 也并不简单。

我很感激你能提供的任何帮助。谢谢!

4

1 回答 1

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

于 2012-05-24T07:07:49.627 回答