I create buttons dynamically from an array. Binding on click event and passing in the button always returns the last button value pressed. How to catch the button variable when you iterate and bind each button.
So I successfully created all the buttons but when I press them I always get the last button pressed?
create buttons dynamically
It’s this:
Each button instance would trigger the event separately.
Or post details if you need more tangible help.
Basically, I need to know what button was pressed. Or to pass the name of the button out.
Yes, I did it like this. But I tried to pass a button name out so I know what button is pressed. If I do it like this I get only the last button name out.
I tried to replicate closure but not successfully. I need to catch each variable of a button so that when it is pressed I get its name.
You’re doing this to one button:
Where are the other buttons?
Or to pass the name of the button out.
Don’t. Instead pass what the button is supposed to do - like an enumerator or some form of ID / or class - depends on what it’s supposed to do in the grand scheme of things
This is in a for loop, this variable is updated each time i create a new button and should supposedly assign on click event to each button that was created.
Answer in the other thread:
You’re mixing things up.
- either use
native buttons
withbuilt in dispatchers
andconstruct
them - or use
user widgets
withcustom dispatchers
andcreate
them. Check the other thread for details
The difference is subtle, unfortunately:
Use the bottom node if you want a user widget with a custom dispatcher that outputs data. I believe that’s what you’re after. It will work for both - native onClick
(after you peel the button) and your own Event Dispatcher
.
I forgot to mention that this is for the editor utility widget. So I don’t have a built in button there. I would need to make a button instead also.
Thank you for your help. Maybe i will go the way and create my own buttons.
editor utility widget
Yeah, they’re a bit special, true that.
@dadika4 Just to clarify, you’re after this, right - a bunch of buttons created dynamically, each spitting out some data via a Dispatcher:
If so:
- the custom button:
- still in the button - the whatever data you may need:
- in the menu that hosts them (here in a vertical box):
So yeah, in case of EUW, you’ll need to construct those objects - my bad.
Hope it helps!