GXT Treepanel 复选框级联无法从叶子向上工作

发布于 2024-10-20 20:02:49 字数 284 浏览 1 评论 0原文

我正在使用带有复选框的 GXT TreePanel,并注意到似乎没有办法配置它,以便检查状态正确地从叶子级联到父节点...示例:

foo
   bar
   baz

Initial state: nothing checked.
Input: check bar, then baz.
Expected result: foo gets checked to reflect that all its child nodes are checked.
Actual result: foo remains unchecked.

I am using a GXT TreePanel with checkboxes and have noticed that there does not seem to be a way to configure it so that check state properly cascades UP from leaves to parent nodes...example:

foo
   bar
   baz

Initial state: nothing checked.
Input: check bar, then baz.
Expected result: foo gets checked to reflect that all its child nodes are checked.
Actual result: foo remains unchecked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔姬 2024-10-27 20:02:49

您可以手动检查是否检查了所有子项,然后再次手动相应地设置其父项的状态。代码会是这样的:

tree.addCheckListener(new CheckChangedListener<ModelData>() {
  public void checkChanged(CheckChangedEvent<ModelData> event) {
    ModelData lastParent = null;
    for (ModelData item : tree.getCheckedSelection()) {
        BaseTreeModel btm = (BaseTreeModel)item;
        if (lastParent != null && btm.getParent() == lastParent) {
            continue;
        }
        boolean allChildrenChecked = true;
        for (ModelData modelData : btm.getParent().getChildren()) {
            if (!tree.isChecked(modelData)) {
                allChildrenChecked = false;
                break;
            }
        }
        tree.setChecked(btm.getParent(), allChildrenChecked);
        lastParent = btm.getParent();
    }
  }
});

You can manually check if all children are checked and then, again manually, set their parent's state accordinaly. The code would be something like this:

tree.addCheckListener(new CheckChangedListener<ModelData>() {
  public void checkChanged(CheckChangedEvent<ModelData> event) {
    ModelData lastParent = null;
    for (ModelData item : tree.getCheckedSelection()) {
        BaseTreeModel btm = (BaseTreeModel)item;
        if (lastParent != null && btm.getParent() == lastParent) {
            continue;
        }
        boolean allChildrenChecked = true;
        for (ModelData modelData : btm.getParent().getChildren()) {
            if (!tree.isChecked(modelData)) {
                allChildrenChecked = false;
                break;
            }
        }
        tree.setChecked(btm.getParent(), allChildrenChecked);
        lastParent = btm.getParent();
    }
  }
});
抠脚大汉 2024-10-27 20:02:49

使用 setCheckStyle(CheckCascade.CHILDREN); 方法。

它会帮助你。

use setCheckStyle(CheckCascade.CHILDREN); method.

it will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文