bitdifferent
12 Jun 2007, 7:02 AM
If you are specifying a callback handler and you want it to receive an extra parameter or two, you need to use 'createDelegate'. you can think of it as being like a 'modified copy' of a function which gets scope and extra params from the delegate definition.
For example: imagine you want to get info from the user via two consecutive messageboxes. You ask question 1, and then question 2, and then you do something based on answer 1 and answer 2.
(Obviously there are other, more compact/cleaner ways to show this, I'm just being verbose):
Ext.MessageBox.prompt('Q1', "Question 1", Answer1Submitted);
function Answer1Submitted(btn, text)
{
if (btn=='ok')
{
Ext.MessageBox.prompt('Q2','Question 2', Answer2Submitted.createDelegate(this, {Answer1: text}, true);
}
}
function Answer2Submitted(btn,text,extra)
{
if (btn=='ok')
{
var Answer2=text;
var Answer1=extra.Answer1;
}
}
I hope this helps someone! Docs for createDelegate are here:
http://www.extjs.com/deploy/ext/docs/output/Function.html#createDelegate
And this is a useful thread on this topic:
http://extjs.com/forum/archive/index.php/t-2135.html
Matt S.
For example: imagine you want to get info from the user via two consecutive messageboxes. You ask question 1, and then question 2, and then you do something based on answer 1 and answer 2.
(Obviously there are other, more compact/cleaner ways to show this, I'm just being verbose):
Ext.MessageBox.prompt('Q1', "Question 1", Answer1Submitted);
function Answer1Submitted(btn, text)
{
if (btn=='ok')
{
Ext.MessageBox.prompt('Q2','Question 2', Answer2Submitted.createDelegate(this, {Answer1: text}, true);
}
}
function Answer2Submitted(btn,text,extra)
{
if (btn=='ok')
{
var Answer2=text;
var Answer1=extra.Answer1;
}
}
I hope this helps someone! Docs for createDelegate are here:
http://www.extjs.com/deploy/ext/docs/output/Function.html#createDelegate
And this is a useful thread on this topic:
http://extjs.com/forum/archive/index.php/t-2135.html
Matt S.