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: 817
Joined: Mon Mar 20, 2006 4:07 pm
Location: Amersfoort, 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: 817
Joined: Mon Mar 20, 2006 4:07 pm
Location: Amersfoort, 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


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests

cron