Dynamic props in menu tree

on onClick I would like to generate dynamic props. Base on event.path list.

For example event.path is [1,0,4], I would like this generate below
self.props.items[1].items[0].items[4].style.classes ='myNewCalss'

I generated it but as string which not working.

== is a comparison operator, not an assignment operator.
Can you share your entire script so we can help?

This code i used onItemClickon menutree component .. I would like to generate the path to style dynamically based on the length of path list and index of the list

def runAction(self, event):
    path_string = 'self.props'
    for index in event.path:
        path_string += '.items[{}]'.format(index)
        path_string += '.style.classes'
        #event.path =[1,0,1]
        #path_string self.props.items[1].items[0].items[1].style.classes = 'mynewClass'

Try this:

def runAction(self, event):
	if event.path:
		target = self.props
		for index in event.path:
			target = target.items[index]
		target.style.classes = 'mynewClass'
2 Likes

Thank a lot Phil .. Perfect :grinning:

Paul?

Typing wrong, Phil ..Corrected

1 Like