如何从 GWT 中的 CellTree 获取所选项目的路径
我有一个包含组织列表的 CellTree。在模型中,每个父级都包含一个子级列表。 有没有一种简单的方法来获取所选项目的路径?或者我必须使用通常的方法,迭代树并按 id 查找。
谢谢
I have a CellTree
containing a list of organisations. In the Model, each parent contains a list of a children.
Is there an easy way to get the path of a selected item ? or I have to go with the usual methode by iterating through the tree and lookup by id.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CellTree 本身没有任何内置功能来检索所选项目的路径。
您必须手动遍历树结构才能获取路径。您可以使用递归函数来检索路径。我已经做了类似的事情,但出于不同的目的(以编程方式打开 CellTree 中的节点)。
The CellTree itself does not have any built-in functionality to retrieve the path for the selected item.
You will have to manually traverse through your tree structure to get the path. You can use a recursive function to retrieve the path. I have done something like that but for a different purpose (programmatically opening nodes in a CellTree).
这不是一个优雅的解决方案。我从业务模型而不是树中获取路径。
Not an elegant solution. I fetch the path from the business model instead of the Tree.
好吧,我希望这听起来不会太明显或错过您正在寻找的内容。但一种思考方法是从选定的节点开始并向上(而不是从根开始向下)。 GWT TreeItems 有一个 getParent() 方法,因此请继续调用它,将您获得的内容添加到列表中,直到您到达根(或什么都没有),这将为您提供一个反向路径作为向上的节点列表,它是唯一的,一个节点只能有一个父节点,然后只需反转列表即可使路径继续下去。
这是一些未经测试的代码,旨在成为 TreeItem 子类的方法(否则您会将节点作为该方法的参数,例如“selectedItem”,然后在整个
Best 中替换 selectedItem,
马丁
Well, I hope this does not sound too obvious or misses what you are looking for. But one way to think about it is to start with the selected node and go up (not to start at the root and go down). GWT TreeItems have a getParent() method so keep calling it, adding what you get to a list, until you hit the root (or nothing) and that will give you a reversed path as a list of nodes going up, it is unique, a node can have only one parent, then just reverse the list to get your path going down.
Here is some untested code aimed to be a method of a subclass of TreeItem (otherwise you'd put the node as a parameter to the method, say 'selectedItem' and then substitute selectedItem for this throughout
Best,
Martin