Hi,

First of all you did not provide the whole for loop.

Second, thats a common beginner mistake in JS.

"var" has always a function scope, not a block scope.

That is why you can use a simple closure that you call in your for-loop:

createHandler : function(zeittyp) {
  return function(evt) {
     console.log(zeittyp);
  };
}

Tino

Am 17.03.2012 um 18:14 schrieb 
[email protected]<mailto:[email protected]>:

Hello,

i  use different values in a for Block like the code below, i want to
shrink this code to  only one   if Block, but when the event appear ,
alwys the last  settings of zeittyp is used . theirfor i use the helpvar
inside the event var zeityp = "xyz". Thsi is the only problem. How can
i  fix this ?

thank you


                    if(zeittyp == "urlaub") {
                        label[zeittyp].addListener("mousedown",
function(e) {
                            var zeittyp = "urlaub";

this.selectedZeittyp.setValue(this.zeittypen[zeittyp]["title"]);

this.selectedZeittyp.setBackgroundColor(this.zeittypen[zeittyp]["bgcolor"]);

this.selectedZeittyp.setUserData("zeittyp",zeittyp);
                            },this);
                        }

                    if(zeittyp == "krank") {
                        label[zeittyp].addListener("mousedown",
function(e) {
                            var zeittyp = "krank";

this.selectedZeittyp.setValue(this.zeittypen[zeittyp]["title"]);

this.selectedZeittyp.setBackgroundColor(this.zeittypen[zeittyp]["bgcolor"]);

this.selectedZeittyp.setUserData("zeittyp",zeittyp);
                            },this);
                        }


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Tino Butz
Softwarearchitekt

1&1 Internet AG - Applications & Integration
Ernst-Frey-Straße 9 · DE-76135 Karlsruhe
Telefon: +49 721 91374-4488
[email protected]<mailto:[email protected]>

Amtsgericht Montabaur / HRB 6484
Vorstände: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Robert Hoffmann, 
Markus Huhn, Hans-Henning Kettler, Dr. Oliver Mauss, Jan Oetjen
Aufsichtsratsvorsitzender: Michael Scheeren



------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to