简体   繁体   English

通过填充 PrimeReact 树需要帮助

[英]Need help by populating a PrimeReact Tree

I'm trying to populate a PrimeReact Tree with data from sqlite3 database, but it doesnt work.我正在尝试使用来自 sqlite3 数据库的数据填充 PrimeReact 树,但它不起作用。

Here is my SQL-Query:这是我的 SQL 查询:

select 'prj:'||p.id as key,p.name as label,(
select json_group_array(json_object('key',key,'label',label))
from(
    select 'tpr:'||tpr.id as key,tpr.name as label from tpr
    where tpr.prjid=p.id
    and tpr.active="true"
    order by tpr.id
    )
    ) as children
from prj p,usr_right r
where p.id=r.prjid
and p.active="true"
and r.usrid=$1
order by p.id

I get following JSON-Code:我得到以下 JSON 代码:

[
{
key: 'prj:1',
label: 'Projekt 1',
children: '[{"key":"tpr:1","label":"Teilprojekt 1"},{"key":"tpr:2","label":"Teilprojekt 2"}]'
},
{ key: 'prj:2', label: 'Projekt 3', children: '[]' },
{ key: 'prj:3', label: 'Projekt 2', children: '[]' }
]

This is OK but i figured out, that the children are not rendered, because there are quotes around the square brackets at the children path - how can i fix this?这没关系,但我发现孩子没有被渲染,因为在孩子路径的方括号周围有引号 - 我该如何解决这个问题?

If initial is your json to be mapped to Tree , then you need to make a slight modification to convert string to array如果initial是将您的 json 映射到Tree ,那么您需要稍作修改以将字符串转换为数组

 let initial = [ { key: 'prj:1', label: 'Projekt 1', children: '[{"key":"tpr:1","label":"Teilprojekt 1"},{"key":"tpr:2","label":"Teilprojekt 2"}]' }, { key: 'prj:2', label: 'Projekt 3', children: '[]' }, { key: 'prj:3', label: 'Projekt 2', children: '[]' } ] let converted = initial.map(obj => ({ ...obj, children: JSON.parse(obj.children)})) console.log(converted)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在打印分形树时需要帮助 - Need help in printing fractal tree 需要使用链接填充2个表单字段的帮助吗? - Need help populating 2 form fields using a link? 通过MVC通过Java脚本填充DropDownList时需要帮助。 列表未填充 - Need Help while Populating the DropDownList via Java Script from MVC. List not populating 需要帮助从二叉树构造带括号的字符串 - Need help constructing string with parenthesis from Binary Tree 需要帮助来了解二叉树的最大深度[Leetcode] - Need help understanding Maximum Depth of Binary Tree [Leetcode] 需要帮助在 React 中使用给定的 json 结构创建文件夹树组件 - Need help creating a folder tree component in React with the given json structure 我需要帮助以php + ajax填充3个依赖的动态文件夹下拉列表 - I need help for populating 3 dependent dynamic folder drop downs with php+ajax 用JSON数据填充jQuery树 - Populating jQuery Tree with JSON data 嵌套的json,需要在angular的帮助下以树结构格式动态显示 - Nested json which need to be display in tree structure format dynamically with the help of angular 在下拉列表中的树状结构中填充许多复选框 - Populating Many checkboxes in tree structure inside Dropdown
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM