I am using the facebook Api to get some album names and their cover photos. From this names and photos i am trying to create a jquery Mobile page that presents them in a list.
Some of my javascript code looks like this :
// Additional initialization code such as adding Event Listeners goes here
FB.api('593959083958735/albums', function(response) {
if(!response || response.error) {
// render error
alert("Noo!!");
} else {
// render photos
for(i=0; i<response.data.length; i++){
albumName[i] = response.data[i].name;
albumCover[i] = response.data[i].cover_photo;
albumId[i] = response.data[i].id;
FB.api( albumCover[i], function(response) {
if(!response || response.error) {
// render error
alert("Noo!!");
} else {
// render photos
document.getElementById('coverPhoto').src = response.picture;
}
});
$("ul").append('<li>'+
'<a href="testFile.HTML" data-transition="slidedown">'+
'<img src= "nothing.jpg" id = "coverPhoto" />'+
'<h2>' + albumName[i] + '</h2>'+
'<p> Test Paragraph</p>'+
'</a>'+
'</li>')
.listview('refresh');
}
}
});
Array AlbumName[]
has the names of the albums , and repsonse.picture
has the cover picture of every album.
As you can see in then i dynamically create a listView with the names and the pictures i get from the call. However THIS is the result . The names of the albums are all ok , but the photos are messed up. On the "network" tab i see that i get all the cover photos from the albums. But it seems that i overwrite the cover photo only in the first cell of the listView. Why though?