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
http://www.servoy-stuff.net
https://www.servoyforge.net
--------------------------------------------
Servoy 5.2.16 / 6.0.9 / 6.1.6 / 7.3.1
All OSes / Java 5 & 6 & 7
User avatar
ptalbot
 
Posts: 1616
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 1 guest

cron