I'm trying to create an ddData object for each element with id #user, but for some reason it is just displaying the last object.
This is my js:
var count = $('*#user').length;
ddData = [];
i = 1;
$.each($('*#user'), function () {
for (i = 1; i <= count; i++) {
$names = $(this).html();
ddData = [{
text: $names,
value: i++,
imageSrc: "images/usuari.png"
}];
console.log($names);
}
});
$('#usuarisLlista').ddslick({
data: ddData,
width: "200px",
imagePosition: "left",
selectText: "Selecciona un usuari"
});
So the console.log(names) output the 3 elements there are (the number of elements can be increased so it can't be a fixed number):
But, it is only displaying the last one:
Can anyone tell me why I am not doing the loop properly? I've tried to find the solution, and I've found in older posts I can use push(), but I can not understand where to add it in my code :S
Thank you!


var $names = $(this).html()