Unable to render data on Tree View Component in perspective

I am using a named query which has data for 11 columns and 55 rows. Data contains parent_id,child_id,ReasonName,hasChild and few other columns. I want to show Name in form of a tree hierarchy .To achieve I have created a script which I am calling on startup event of root in perspective view and I am binding item property of tree component using my script. But its not showing the tree component in preview and all the nodes for item are not reflecting.It only takes last node in item. Attaching screenshot and script for reference.

Can anyone please help me as I am new to ignition.

Thankyou!!

def runAction(self):

						
						data = system.db.runNamedQuery("GetReasons",{
						"treeid":1
						})
						if not data:
							system.perspective.print("No data found")
							return 
						
						tree_dict={}
						
						for row in data:
							child_id = row["child_id"]
							parent_id = row["parent_id"]
							reason_name = row["ReasonName"]
							if parent_id is None or parent_id == 1:
									node ={
									    				"label":reason_name,
									                    "expanded":False,
									                    "data":{
									                    "child_id":child_id,
									                    "HasChild":row["HasChild"]
									                    },
									                    "items": []
									                    }  
						 
			  
						if parent_id not in tree_dict:
					
							tree_dict[parent_id] = []
							
						tree_dict[parent_id].append(node)

						self.getChild("Tree").props.items= tree_dict


1 Like

The warning is pretty clear: items is supposed to be an array, but your script results in items having a dict type.

self.getChild("Tree").props.items= tree_dict
2 Likes