Skip to content

隐藏节点无效 #112

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
xtuer opened this issue Nov 18, 2024 · 2 comments
Open

隐藏节点无效 #112

xtuer opened this issue Nov 18, 2024 · 2 comments

Comments

@xtuer
Copy link

xtuer commented Nov 18, 2024

Bug 描述
参考文档里 VTree Data Fields 的说明,visible 为节点是否可见。
实际情况是 visible 为 false 时仍然显示到界面上。

复现步骤
隐藏节点无效:

  • 创建节点的时候,把 visible 设置为 false,节点一样会显示出来 (没有使用 :data 的方式绑定,而是使用 setData() 的方式)。
  • 创建节点不修改 visible 的值 (默认为 true,console.log 里输出来看到的),点击界面上的按钮,把节点的 visible 设置为 false 然后调用 treeRef.value.clearChecked() 节点也没有隐藏。

上面的操作如果修改的是节点的 disabled 属性的话是生效的。

期望表现
设置 visible 为 true 时节点可见,设置 visible 为 false 时节点不可见。

实际表现
设置 visible 无效。

组件版本

  • @wsfe/vue-tree": "^3.2.1"
@xtuer
Copy link
Author

xtuer commented Nov 18, 2024

更新到 "@wsfe/vue-tree": "^4.1.1" 后,可以使用下面的方式隐藏和显示节点了,但是创建节点是 visible = false 的节点仍然会显示出来。

let vn: any; // 需要把 children 缓存起来,否则 n.visible = false 后 children 会被清空,比较奇怪的逻辑。
function toggleSystemTables(): void {
    for (const n of treeRef.value.getFlatData()) {
        if (n.title === 'information_schema') {
            console.log(n);

            // 隐藏之前缓存节点的 children。
            if (n.visible) {
                vn = [...n.children]
            }

            // 隐藏节点。
            n.isLeaf  = false;
            n.visible = !n.visible;
            treeRef.value.updateNode(n.id, n);

            // 节点可见时重新更新 children。
            if (n.visible) {
                treeRef.value.updateNode(n.id, { children: [...vn] });
            }
        }
    }
}

@xtuer
Copy link
Author

xtuer commented Nov 19, 2024

目的是根据条件动态的在需要的时候隐藏和显示节点,而不是删除节点。

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant