如果孩子存在,如何只显示一个TreeView展开符号[+] [英] How to only display a TreeView expand sign [+] if children exist

查看:344
本文介绍了如果孩子存在,如何只显示一个TreeView展开符号[+]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个应用程序,从数据库中的层次数据填充树视图。



我设计它使用延迟加载,



我的问题是,显然我不知道一个节点是否有孩子,除非我调用数据库和外观。目前我已经实现了一个虚拟子节点,所以对所有节点出现[+]图标,然后删除这个虚拟节点,并在 BeforeExpand 事件中获取真正的子节点。



这意味着对于没有子节点的节点,我得到一个[+]图标,因此用户点击展开图标,没有什么显示哪个外观有点



在延迟加载树视图中处理子节点的预处理方法是什么?如果我调用数据库来查看是否有子节点,那么我可能只是加载子节点并忘记延迟加载吗?



一个想法已经在数据库中存储了一个HasChildren标志,因此我可以选择性地为实际具有子节点的节点创建我的虚拟子节点。



对不起,我很想看看别人的想法...

解决方案

您调用,检查子节点数据:

  SELECT tp。*,
$ b SELECT 1
FROM table tc
WHERE tc.parent = tp.id
LIMIT 1
)AS has_children
FROM table tp



您不必计数,可能会很长。



只需检查是否至少存在一个孩子。


I've developed an application that populates a treeview from hierachical data in a database.

I've designed it to use lazy-loading so it only gets the child nodes when a node is expanded.

My problem is that obviously I don't know if a node has children unless I make a call to the database and look. Currently I have implemented a dummy child node, so that the [+] icon appears for all nodes, I then remove this dummy node and get the real child nodes in the BeforeExpand event.

This means I get a [+] icon for nodes that don't have child nodes, so the user clicks the expand icon and there's nothing show which looks a bit shoddy.

What is the preffrred method for handling child nodes in a lazy-load treeview? If I make a call to the database to see if there are child nodes then I might as well just load the child nodes and forget about lazy loading right?

One thought I had was to store a 'HasChildren' flag in the database, so I can selectively create my dummy child node only for the nodes that actually do have child nodes.

Sorry for rambling on, I'm very interested to see what other people think...

解决方案

When you make a call, check for children along with the node data:

SELECT  tp.*, 
        (
        SELECT  1
        FROM    table tc
        WHERE   tc.parent = tp.id
        LIMIT 1
        ) AS has_children
FROM    table tp

You don't have to count, it may be long.

Just check that at least one child exists.

这篇关于如果孩子存在,如何只显示一个TreeView展开符号[+]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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