PDA

View Full Version : javascript problem



kyuzo
20 May 2006, 08:37 AM
Any javascript guru that can have a look at the folowing code?

window.application.main = function(){
var d = this.getClientWindow().getClientDocument();
var bs = new QxBarView;
for(var i=[0];i<[3];i++){
var bvb = new QxBarViewButton("page"+i, [0]);
bs.getBar().add(bvb);
var p = new QxBarViewPage(bvb);
var galleryList = [];
galleryList.push({
width : [350],
height : [350],
thumbWidth : [64],
thumbHeight : [64],
comment : "comment",
title : "title",
src : "pic.gif"
});

var gallery = new QxGallery(galleryList);
gallery.id=i;
gallery.addEventListener("click", function(e){
alert(gallery.id);
});

p.add(gallery);
bs.getPane().add(p);
}
d.add(bs);
}

it uses qooxdoo.
basically, what this code is doing is creating 3 galleries and adding 3 event handlers to them; whenever i click a gallery, i expect to get a message box containing the id of that gallery. however, no matter what gallery i click, i get the last added gallery id, 2.
i have the feeling that this isnt a qooxdoo lib issue, but my bad understanding of how js works. i would expect that clicking the 1st gallery to see 0, the 2nd 1 and so on.
anyone that can shed some light on this?

kyuzo
22 May 2006, 03:17 PM
I got it working, if anybody is interested.

gallery.addEventListener("click", function(e){
//alert(gallery.id);
alert(this.id);
});