cancel
Showing results for 
Search instead for 
Did you mean: 

Why does sap.m.Tree render all nested objects as nodes? Can it be prevented?

rsletta
Contributor
589

We have a project where we need to list a hierarchy of messages, and thought sap.m.Tree would be a good candidate for the job. But when loading the data, which is a nested object, we found out that it renders a node for all objects. In out data set To, From, and MessageDate is objects, and those are responsible for the empty nodes in my example. Since this behaviour is present in all recent versions of UI5, we assume this is by design.

Why is this happening? And is there a way to prevent this, or will I have to find another solution for my example? I have searched the docs, and looked into the lib source code, but haven't found any clues.

A live example can be found on Plunker, at https://next.plnkr.co/edit/Qa0vWsHlDrjAzHRq

View Entire Topic
voyager
Product and Topic Expert
Product and Topic Expert

You can specify the arrays that should be displayed by the tree. By default, all arrays are displayed as nodes, I guess the table also displays each entry from the "features" array as its own node, but these object do not match the binding templates, hence the empty nodes. You are looking for the parameter arrayNames from JSONTreeBinding.

Try this as your binding syntax:

items="{path: '/features', parameters: {arrayNames: ['nodes']}}"
rsletta
Contributor

You are magnificent Nicolas!

This was the piece of information I was missing, Thank you for guiding me towards the right solution, and referring to the documentation. It's easy to get lost sometimes. ☺️