PDA

View Full Version : What is the method for defining input variables for handlers?



maya
30 Apr 2007, 1:28 PM
Hi,

I have a function (e.g., test(x,y)) that invokes a message in the following way:

function test(x,y)
{
Ext.Msg.show({
title:'test',
msg: 'test',
buttons: Ext.Msg.OK,
fn: "myHandler"});
}

and I would like to pass x,y to myHandler, so I can use them in this function.

How can it be done?

Thanks

DigitalSkyline
30 Apr 2007, 2:08 PM
maya,
I submitted the very same query about ten posts down from you:
http://extjs.com/forum/showthread.php?t=5510
Tim was helpful in pointing out that the question has been covered already here:
http://extjs.com/forum/showthread.php?t=4395

its pretty simple once you see it, but if you have questions in the implementation I'd be happy to help.

maya
1 May 2007, 6:24 AM
Thanks.

From the link you sent, I understand that I can add my vars in the "createDelegate" part, but I can't understand the order in which I receive them in my handling function.

For example, if I write:
Ext.Msg.show({...
fn: myHandler.createDelegate(this,[{pr_id:pr_id, pr_parent_id:pr_parent_id}],true)
...});

unction myConfirmDeleteHandler(item, e, args){
...
}

In debug mode I see that item holds the button I pressed, e is "", and args (the 3rd var) holds the values I entered in the 2nd var in the
"myHandler.createDelegate" line (the pr_id and .pr_parent_id values).

Why the order was mixed?

Thanks

Animal
1 May 2007, 6:31 AM
You passed the third parameter to createDelegate as true. Doing this, or omitting it means that the argument array is appended to any existing arguments. So the Msg passes its handler two arguments, "item" and "e". And you append yours.

BTW, I wouldn't bother wrapping them, I'd use:



function myHandler(item, e, pr_id, pr_parent_id){
...
}

Ext.Msg.show({...
fn: myHandler.createDelegate(this, [pr_id, pr_parent_id])
});

DigitalSkyline
1 May 2007, 10:54 AM
Or using your syntax



function test(item,e,args)
{
pr_id = args.pr_id
pr_parent_id = args.pr_parent_id

Ext.Msg.show({
title:'test',
msg: 'test',
buttons: Ext.Msg.OK,
fn: "myHandler"});
}



"args" is passed as an associative array.

maya
8 May 2007, 11:06 PM
Thanks - this was helpful.