On Wed, Sep 1, 2010 at 06:00, Tranninger Harald <[email protected]>wrote:
> Hi @ All,
>
>
> I have a strange Problem. My App creates some buttons out of a database.
> I get a table with all button-information out of a Msql Database via RPC
> and PHP Backend.
> Further I store the information in some Datastructure.
> So far it is not a problem at all.
>
> No I want to add all the buttons to the desktop. To do so, I implemented a
> "for" loop.
>
> for (var i=0; i < array.getLength(); i++)
> {
> var button_new = new qx.ui.form.Button(label, icon);
>
> button_new.addListener("dblclick", function(e) {
> //Do something if button 1
> //Do something else if button 2
> //Do something else if button 3.....
> },this);
>
> desktop.add(button_new , left: 50+(10*i), top:
> 50+(10*i)});
>
> }
>
> This code above is just a sample code and does not include all detailed
> code, needed to run this.
>
It's generally better if you _do_ provide the detail of a full playground
snippet, if at all possible. In this case, I suspect that your listener does
not save the loop variable value, thus causing your problem. Try something
like this:
for (var i=0; i < array.getLength(); i++)
{
var button_new = new qx.ui.form.Button(label, icon);
button_new.setUserData("buttonNumber", i); // save the button number of
this button
button_new.addListener("dblclick", function(e) {
switch(this.getUserData("buttonNumber"))
{
case 0:
// handle button 0
break;
case 1:
// handle button 1
break;
...
}
},button_new);
desktop.add(button_new , left: 50+(10*i), top: 50+(10*i)});
}
Instead of userData, you could also do this using a closure. What I showed
is a bit clearer if you're not totally acquainted with closures.
Derrell
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel