PDA

View Full Version : buttons function



Alien
2 Oct 2010, 6:31 AM
Here's the code:

buttons: [{
text: 'Button',
handler: function() {
updateSpot.createDelegate(p1, ['panel1'])
}
}]updateSpot.createDelegate(p1, ['panel1']) - this function does not work in function(){}

but all the work without the function(){}

that is, so running:


buttons: [{
text: 'Button',
handler: updateSpot.createDelegate(p1, ['panel1'])
}]what's the problem?

Animal
2 Oct 2010, 9:18 AM
Read what you code does.

It either sets the handler to be a function which just creates a delegate function which, if ever called, would invoke the updateSpot method.

Or it sets the handler to be a delegate function which, when called, invokes the updateSpot method.

You have to read what your code DOES.

laurentParis
2 Oct 2010, 9:23 AM
the problem is not with extjs. You need to study some javascript's particularity
look at this book about invocation pattern !
(add http)://books.google.fr/books?id=PXa2bby0oQ0C&lpg=PP1&dq=crockford&pg=PA28#v=onepage&q&f=false

plalx
2 Oct 2010, 1:57 PM
The createDelegate() function returns a function that will call the source function in the specified scope with the specified arguments. So calling Function.createDelegate() returns a new function but doesn't call/execute that new function.

Alien
2 Oct 2010, 8:29 PM
I do not understand you.
The code can be found here: http://dev.sencha.com/deploy/dev/examples/core/spotlight.html
Here I need in addition:

handler: updateSpot.createDelegate (this, ['panel2'])
perform other functions, and it does not

laurentParis
3 Oct 2010, 12:24 AM
buttons: [{
text: 'Button',
handler: function (updateSpot, p1) { return function() {
updateSpot.call(p1, 'panel1');
};}(updateSpot, p1)
}]

Alien
3 Oct 2010, 12:34 AM
handler: function (updateSpot, p1) { return function() {
updateSpot.call(p1, 'panel1');
p1.buttons[0].setDisabled(true);
};}(updateSpot, p1)
does not work

laurentParis
3 Oct 2010, 1:07 AM
if this code work :


buttons: [{
text: 'Button',
handler: updateSpot.createDelegate(p1, ['panel1'])
}]


this code work too


buttons: [{
text: 'Button',
handler: function() {
updateSpot.call(p1, ['panel1']);
}
}]


this code work too


buttons: [{
text: 'Button',
handler: function (updateSpot, p1) { return function() {
updateSpot.call(p1, 'panel1');
};}(updateSpot, p1)
}]


this code work too


buttons: [{
text: 'Button',
handler: function() {
updateSpot.createDelegate(p1, ['panel1'])();
}
}]


if not, it's because the first code that you give us for example is not work. So with bad information we can't help you !

plalx
3 Oct 2010, 11:56 AM
Just explain to us what the code should do when you click on the button...?

Alien
3 Oct 2010, 7:28 PM
when you press the button to turn it off as
p1.buttons[0].setDisabled(true);

plalx
4 Oct 2010, 5:18 AM
Hum? Well if disabling the button is the only thing you want...



handler: function(b) {
b.setDisabled(true);
}


Don't you want to do anything else?

Alien
4 Oct 2010, 11:50 PM
Hum? Well if disabling the button is the only thing you want...



handler: function(b) {
b.setDisabled(true);
}
Don't you want to do anything else?

I said, I need to disable the button and make createdelegate simultaneously, but does not work
I need this:

handler: function(b) {
updateSpot.createDelegate(p1, ['panel1'])();
b.setDisabled(true);
}

Condor
5 Oct 2010, 12:20 AM
Just a note:

updateSpot.createDelegate(p1, ['panel1'])()
should be written as

updateSpot.call(p1, 'panel1');

Alien
5 Oct 2010, 1:01 AM
Just a note:

updateSpot.createDelegate(p1, ['panel1'])()
should be written as

updateSpot.call(p1, 'panel1');

handler: function (b) {
updateSpot.call(p1, 'panel1');
b.setDisabled(true);
}
does not work disable