I have been stuck on this problem for the whole day! Basically, I have this array:
var category = {
id_1:[
{id:"1_1", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"8,50", link:""},
{id:"1_2", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"7,00", link:""},
{id:"1_3", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"7,00", link:""},
{id:"1_4", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"19,00", link:""},
{id:"1_5", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"10,00", link:""},
{id:"1_6", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"8,50", link:""},
{id:"1_7", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"12,00", link:""},
{id:"1_8", img:"img/prodotti-categorie/test.jpeg", titolo:"Name", prezzo:"7.50", link:""}],
id_2:[...
Then I get values like this:
for(var i=0, l=Object.keys(category["id_"+(cat_id)]).length; i<l; i++) {
var img = category["id_"+(cat_id)][i]["img"];
var title = category["id_"+(cat_id)][i]["titolo"];
var price = category["id_"+(cat_id)][i]["prezzo"];
$('#content').append('<div class="category-list item-'+ cat_id + '_' + i +'"><img src="' + img + '"><p>' + title +'</p><p>€' + price + '</p></div>');
//From here begins my problem:
//When i search fot the class added before and try to append or do anything else, variable i is always 8!
$('.item-' + cat_id + '_' + i).click(function(){
app.renderPageProductView(cat_id, i);
});
};
I need to append to every <div> element with a class such as class="item-1_1" a function on click app.renderPageProductView(1,1);
Anybody has a solution? Thanks!