How to make a Tag Browse Tree in Perspective?

Hi all,

I am trying to use a tag browse tree in perspective, but I cannot find the corresponding component.

In Vision:

In Perspective:

I could not configure the Perspective Tree to display tags. Does anyone know a script that can populate the props.items array?

Thank you!

	# Recursively builds a tag tree, starting from the specified path
	def tagTree(path):
		tagTreeList = []
		newItem = {}
		# Browse the curent path.		
		results = system.tag.browse(path)
		# Add each tag that was found to a new item.
		for result in results.getResults():
			newItem['label'] = result['name']
			newItem['data'] = result['fullPath']
			# If the tag has children, browse and add each of the children to the item.
			if result['hasChildren']:
				newItem['items'] = tagTree(result['fullPath'])
			# Once all children have been added to the item, add the new item to the list.
		# After all items under the path have been added to the list, return the list.	
		return tagTreeList

I couldn’t find this answered anywhere on the forum, here’s what I came up with.


This is how I did it too. It can take quite a bit of time to load if you are going to a directory with a few different folders/UDTs.

Where are you calling this script from to populate the items property?

There’s a couple different ways to set this up.

From a script transform:

  1. Add a custom property to your Tree component named something like ‘rootPath’.
  2. Add a binding to your Tree’s ‘items’ property, binding it to your new custom ‘rootPath’ property followed by a script transform.
  3. Call the tagTree() function in this script transform with your ‘rootPath’ property as the input.

On page load:

  1. Add ‘onStartup’ script to your view.
  2. In this script, call the tagTree() function with your desired path to generate the tagTree list.
  3. Then use the script to set your Tree component’s ‘items’ property to the tagTree list.
1 Like

Awesome, i ended up going with the script transform.


1 Like

First, thanks so much for this Ben, this is exactly what I needed.

One note – newItem should be initialized under the for result in results.getResults(): loop. Otherwise, if the next tag in the list does not have any children, it just inherits the ‘items’ from the previous tag.

1 Like