You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the best way to convert it into required TreeData format?
(like: {title: ..., children:[ ... ]}))
Can we use nodeRenderer to achieve this?
Thanks
Anil
The text was updated successfully, but these errors were encountered:
anil1712
changed the title
What is the best way to render custom TreeData
What is the best way to render Tree using custom Tree Object JSON
Feb 14, 2017
As all of the helper functions also use children as the key for children, I would suggest you convert it temporarily. Try this function:
constconvertChildrenKeys=(children,prevKey,nextKey)=>{returnchildren.map(child=>{constmodifiedChild={name: child.name,// carry over whatever other props you want};// If this child has children, add them using the nextKeyif(child[prevKey]&&child[prevKey].length>0){modifiedChild[nextKey]=convertChildrenKeys(child[prevKey],prevKey,nextKey);}returnmodifiedChild;});};// Convert your data to a form that can be handled by react-sortable-treeconstcompatible=convertChildrenKeys(myTreeData,'users','children');// ... // After you're done using the library,// convert the data back to its original format (if you need to)constoriginal=convertChildrenKeys(compatible,'children','users');
By the way, nodeRenderer is entirely for visual customization. For example, if you wanted to render rows without borders, add buttons anywhere, etc.
Hi,
I am having the Tree Data in this format. (eg.
{name: ..., users: [ ... ]}
)What is the best way to convert it into required TreeData format?
(like:
{title: ..., children:[ ... ]})
)Can we use
nodeRenderer
to achieve this?Thanks
Anil
The text was updated successfully, but these errors were encountered: