Per essere sicuro: la funzione onImageClick dentro il ciclo for viene ricreata a ogni iterazione, giusto?
this._buildImageGallery = function()
{
var table = new ElementBuilder("table")
.getElement();
var row = new ElementBuilder("tr").getElement();
table.appendChild(row);
for(var k=1; k <= this._paths.length; k++)
{
var path = this._paths[k - 1];
var image = new ElementBuilder("img")
.withAttribute("src", path)
.withAttribute("height", "50")
.withAttribute("width", "50")
.withStyle("cursor", "pointer")
.withClickEventListener(onImageClick)
.getElement();
row.appendChild(new ElementBuilder("td").withChild(image).getElement());
if(k % 8 == 0)
{
//table.appendChild(row);
row = document.createElement("tr");
table.appendChild(row);
}
function onImageClick()
{
This._setPath(path);
}
}
var container = new ElementBuilder("div")
.withStyle("backgroundColor", "#616161")
//.withStyle("width", "100%")
.withChild(table)
.getElement();
this._container.appendChild(container);
}E dunque perché parrebbe che l'event handler di ogni immagine sia legato a una funzione con la stessa path? Cioè, la path che viene passata al metodo setPath è sempre la stessa, per ogni immagine.