构建动态层次结构
我有一个查询返回以下格式的行:
ID NAME PARENTID
1 Top level. 0
7 Second level1. 1
10 Third Level under Second Level1. 7
22 Second Level2. 1
23 Third Level1 under Second Level2. 22
24 Third level2 under Second Level2. 22
我想要做的是动态构建一个结构。上述数据需要按以下层次结构进行组织:
Top Level.
Second Level1.
Third Level under Second Level1.
Second Level2.
Third Level under Second Level2.
Third Level under Second Level2.
数据可以是任何内容,并且层次结构的深度没有限制。我正在寻找一种编程方式来将这些数据组织成一个结构,无论查询返回什么。我正在 ColdFusion 中编写此内容,因此如果您有 CF 示例那就太好了,但伪代码也可以。感谢您的帮助。
I have a query that returns rows in the following format:
ID NAME PARENTID
1 Top level. 0
7 Second level1. 1
10 Third Level under Second Level1. 7
22 Second Level2. 1
23 Third Level1 under Second Level2. 22
24 Third level2 under Second Level2. 22
What I want to do is dynamically build a structure. The above data would need to be organized in the following hierarchy:
Top Level.
Second Level1.
Third Level under Second Level1.
Second Level2.
Third Level under Second Level2.
Third Level under Second Level2.
The data could be anything and there is no limit to the depth of the hierarchy. I'm looking for a programmatic way of organizing this data into a structure no matter what is returned from the query. I'm writing this in ColdFusion so if you have CF examples that would be nice but pseudocode would be fine. Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用该函数并传入0作为parentID和q_query的查询结果。
Call this function and pass in 0 for the parentID and the query result for q_query.