invalid parent_id when using add_node #331
-
Hello there, First of all im still learning lua and just started with my current project (a bitbucket reviewer).
So i thought this might be because its not a uuid so i just google and fully copied from here https://gist.github.com/jrus/3197011 But still im getting this issue. I tried for both "methods" to cast to a string with tostring(value) but this still didnt solve the issue. So the full function which is causin the issue is down below following
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
The second parameter of So when you're calling Instead of adding one node at a time, you can create a map first: local nodes_by_parent_id = { _root = {} }
for _, value in ipairs(values) do
local html = value["content"]["html"]
local author = value["user"]["display_name"]
local id = value["id"]
local parent_id = value["parent"] and value["parent"]["id"] or "_root"
if not nodes_by_parent_id[parent_id] then
nodes_by_parent_id[parent_id] = {}
end
table.insert(nodes_by_parent_id[parent_id], {
html = html,
author = author,
id = id,
})
end and then add those to the tree: tree:set_nodes(nodes_by_parent_id._root)
for parent_id, nodes in pairs(nodes_by_parent_id) do
if parent_id ~= "_root" then
tree:set_nodes(nodes, parent_id)
end
end and render: tree:render() |
Beta Was this translation helpful? Give feedback.
Here's a rough draft for you to get started: