Pass parameter to .addMenuItem method?

Questions, tips and tricks and techniques for scripting in Servoy

Pass parameter to .addMenuItem method?

Postby john.allen » Thu Jul 12, 2012 3:31 am

I have a series of methods available in a dropdown menu (created with plugins.window.createPopupMenu()). For one of these methods I would ideally like to pass a parameter with it. As you know the syntax for ".addMenuItem" though just allows for passing the name of the method (without the parentheses following the name) as otherwise it would execute when the dropdown itself is activated. I can't see any way to pass a parameter to the method but does anyone know any way of doing that?
John Allen
Stanford University
john.allen
 
Posts: 515
Joined: Wed Jul 02, 2003 10:07 pm
Location: Stanford CA USA

Re: Pass parameter to .addMenuItem method?

Postby ptalbot » Thu Jul 12, 2012 4:50 am

The addMenuItem returns a MenuItem object.
You can then use the methodArguments to set the array an array of objects you want to pass to the method.

Code: Select all
var popupMenu = plugins.window.createPopupMenu();
var menuItem = popupMenu.addMenuItem('aName', aMethod);
menuItem.methodArguments = [1, true, 'whatever'];


Note that the array elements will be passed as arguments 5, 6 and so on to the callback method.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Pass parameter to .addMenuItem method?

Postby john.allen » Thu Jul 12, 2012 9:25 am

Thanks so much Patrick. I missed that somehow. But with your pointer I just clicked on MenuItem and then the property of methodArguments in the documentation... Somehow I was thinking the argument construction would simply show in addMenuItem.
John Allen
Stanford University
john.allen
 
Posts: 515
Joined: Wed Jul 02, 2003 10:07 pm
Location: Stanford CA USA


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests