【发布时间】:2021-04-01 03:51:49
【问题描述】:
我正在使用一个可以在搜索后使用的过滤器,这样我就在数据库中创建了一个表并插入了一些类别及其子类别,现在我想将所有这些组合成一个树状结构。但我坚持这个
现在我怎样才能做到这一点?
[
{
"parent_category": "Recruitment",
"category_name": "Job description"
},
{
"parent_category": "Recruitment",
"category_name": "Forms"
},
{
"parent_category": "Performance management system",
"category_name": "Job description"
},
{
"parent_category": "Exit",
"category_name": "Job description"
}
]
对于这种类型的结果:
[
{
"parent_category": "Recruitment",
"category_name": "Job description, Forms"
},
{
"parent_category": "Performance management system",
"category_name": "Job description"
},
{
"parent_category": "Exit",
"category_name": "Job description"
}
]
不使用长类型的 for 循环,因为它消耗更多时间。
【问题讨论】:
-
第一个结果应该是 category_name:
Forms, Forms你的例子,不是吗? -
请仔细检查您的示例
-
问题已编辑