How do you populate a treeview in perspective, I could not find any documentation on how to do it

Hello, I am trying to populate a treeview in perspective and I've been trying for the last 3 days and I can't seem to find a solution and I have yet to see any examples on how to implement it.

Here's what I did:

  • I used a query binding that is tied to items.


    I get an error at the top that reads "items: string found, array expectd". Isn't my query a dataset, so it should not be throwing that error?

  • I used a button to run the query and then throw the results in the tree.items property.

	data =system.db.runNamedQuery('Test_Path')
	lis =[]
	
	for item in data.getColumnAsList(0):
		lis.append(item)
		

	self.getSibling("Tree").props.items = lis
	

I was on the documentation page for the Component and there is a .separationCharacter function that I don't know how to use I've tried adding this as property and I just cant get it to work.

My folder paths ar formated as such: \parentPath\child1\child2
I've also replaced the '' with '/' because I saw somewhere that the default seperation path is '/'.

You need an array of objects (python dictionaries) in the format described here in the manual:

If you want the tree to be nested, you will have to set that up yourself. The component won't automatically figure out how to parse through the paths that you pass to it.

The items prop of the tree is a list of objects. Each of those objects has the props: label, expanded, data, items. That items prop is another list of objects in the exact same format. And so on.

You'll have to write some python code to go through your paths and create the structure that the tree component expects.

1 Like

Thank you, I will continue to work on it.

You may find my post below helpful. The Tree component (not Treeview as you have in your title) is tricky because the 'items' property is recursive.

1 Like