带复选框的 GWT 树:如何获取所有选中的树项目?
我正在使用 GWT 2.3。在我的应用程序中,我使用带有复选框的 GWT Tree。 这是我创建树的代码
formTree = new Tree();
if (formList != null && formList.size() > 0) {
for (Form form : formList) {
TreeItem item = new TreeItem(new CheckBox(form.getName()));
formTree.addItem(item);
}
}
在这棵树中,我为每个树项目使用复选框。现在,单击按钮我想要所有选中的树项目。我没有得到如何获取所有选定的树项目。请帮助我。提前致谢。
I am using GWT 2.3.In my application I am using GWT Tree with check box.
Here is my code to create tree
formTree = new Tree();
if (formList != null && formList.size() > 0) {
for (Form form : formList) {
TreeItem item = new TreeItem(new CheckBox(form.getName()));
formTree.addItem(item);
}
}
In this tree I am using check box for every tree item. now on a click of button I want all the checked tree items.I am not getting How can i get all the selected tree item.Please help me out.Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议扩展
TreeItem
来满足您在这里的实际目的:让它创建基于复选框的项目,它允许您访问复选框值。目前,您必须循环遍历,取出每个的子级,转换为 Checkbox 类,然后检查属性。这些都不是好的做法,因此扩展它确实是唯一明智、高效且有效的方法。话虽如此,如果您确实必须这么做,您可以这样做:
I suggest extending
TreeItem
to serve the actual purpose you're intending here: have it create checkbox-based item, which allows you to access the checkbox value. Currently, you'd have to loop through, get out the child of each, cast to the Checkbox class, then check the property. None of this is good practice, so extending it is really the only smart, efficient and effective way to go.With that being said, here's how you might do it if you really had to: