When you define a function in a 'for' loop using the loop variable, all
functions will have a *reference* to that variable, not a copy. Example:

for (var i=1;i<=5;i++{
  function () {
    return i;
  }
}

If you captured those inner functions and called them after the loop has
terminated, they would all return 5. Hence your choice using a helpvar is
exactly right. By this you get a *copy* of the current value into your
function.

Other than that, there is nothing to stop you from using a generic event
handler:

    label[zeittyp].addListener("mousedown", function (e) {
        var lzeittyp = zeittyp;
        this.selectedZeittyp.setValue(this.zeittypen[lzeittyp]["title"]);
        ...

I suggest using a different name for the local variable, though (like
"lzeittyp" in this code snippet).

T.


> 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
>
>
>



------------------------------------------------------------------------------
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