methodArguments popupMenu

Questions, tips and tricks and techniques for scripting in Servoy

methodArguments popupMenu

Postby DEK4 » Thu Aug 09, 2012 10:55 am

Hello,
i try to pass an argument to my function with popupmenu but nothig...

this is my menu:

Code: Select all
var menu = plugins.window.createPopupMenu()
_sub = menu.addMenuItem()
_sub.text = 'text'
_sub.setMethod(new1)
_sub.methodArguments = [1, "data"]


my function:
Code: Select all
function new1(args) {
   application.output(args[0])
}


i want to pass also the event is it possible?

thanks
User avatar
DEK4
 
Posts: 111
Joined: Wed Oct 12, 2011 9:26 am

Re: methodArguments popupMenu

Postby Joas » Thu Aug 09, 2012 1:06 pm

There are a couple of default arguments that will always be passed to a method triggered by the popupmenu, your argument will start at index 5.
See the comment in the sample code:
Code: Select all
// set the arguments to be sent to the callback method
// (an array of elements which will be passed as arguments 5, 6 and so on to the callback method)
// the first 5 arguments are fixed:
//   [0] item index
//   [1] parent item index
//   [2] isSelected boolean
//   [3] parent menu text
//   [4] menu text
entry.methodArguments = [17, "data"];
Joas de Haan
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 834
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: methodArguments popupMenu

Postby DEK4 » Thu Aug 09, 2012 2:43 pm

Thanks for your answer.
I tried but nothig...it prints <null>


Code: Select all
_sub.methodArguments = ['asd', "data", 'pippo']


Code: Select all
/**
* @param {Array} args
* @properties={typeid:24,uuid:"30649593-2E51-4B39-AA5B-F67CB2EDE3BD"}
*/
function call(args) {
   for (var index = 0; index < args.length; index++) {
      application.output(args[index])
   }
   
}
User avatar
DEK4
 
Posts: 111
Joined: Wed Oct 12, 2011 9:26 am

Re: methodArguments popupMenu

Postby Joas » Thu Aug 09, 2012 3:17 pm

You expect the first argument to be an array, but that is not correct. All those values will be separate arguments.

Try this:
Code: Select all
function call(index, parentIndex, isSelected, parentText, text, yourFirstArgument, ....) {
   ...
}
Joas de Haan
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 834
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: methodArguments popupMenu

Postby DEK4 » Thu Aug 09, 2012 4:30 pm

Thanks...it works!!
User avatar
DEK4
 
Posts: 111
Joined: Wed Oct 12, 2011 9:26 am

Re: methodArguments popupMenu

Postby Westy » Mon Jan 04, 2021 7:18 pm

After eight years of not being able to pass parameters with the popupMenu I today stumbled upon this post (THANK YOU).

The following now works for me:

Code: Select all
/**
* @properties={typeid:24,uuid:"A43C20A4-35FE-4F93-8F4E-16B5A28D5689"}
*/
function showpopup(event) {
   var popupmenu = plugins.window.createPopupMenu()

   var menuitem1 = popupmenu.addMenuItem('Menu Text', globals.myGlobalMethod)
   //add arguments to the method call
   menuitem1.methodArguments = ['myInfo']

   var source = event.getSource()
   if (source != null) {
      popupmenu.show(source);
   }
}


Code: Select all
/**
* @param {String} itemIndex0
* @param {String} parentItemIndex1
* @param {String} isSelectedBoolean2
* @param {String} parentMenuText3
* @param {String} menuText4
* @param {String} arg5
*
* @properties={typeid:24,uuid:"77930261-9675-4270-A5AC-F4EC3E1BDB96"}
*/
function myGlobalMethod(itemIndex0, parentItemIndex1, isSelectedBoolean2, parentMenuText3, menuText4, arg5) {
   application.output(arg5);
}


Dean Westover, President
Choices Software, Inc.
Westy
 
Posts: 849
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: methodArguments popupMenu

Postby Joas » Tue Jan 05, 2021 10:06 am

Haha, glad to have helped! :)
Joas de Haan
Yield Software Development: Need help on your project?
yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 834
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL


Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests