带有复选框的GWT树:如何获取所有选中的树项? [英] GWT tree with checkbox:How to get all checked tree items?

查看:69
本文介绍了带有复选框的GWT树:如何获取所有选中的树项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GWT 2.3.在我的应用程序中,我正在使用带有复选框的GWT树. 这是我创建树的代码

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.

推荐答案

我建议扩展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:

for(int i = 0; i < tree.getItemCount(); i++) 
{
    TreeItem item = tree.getItem(i); 
    CheckBox itemCheckBox = (CheckBox)item.getWidget();
    boolean checkBoxValue = itemCheckBox.getValue().booleanValue();
    // do something w/ checkBoxValue...
} 

这篇关于带有复选框的GWT树:如何获取所有选中的树项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆