So my function is insanely simple right now…
setUpButtons: function(items) {
console.log(typeof items); //Logs Object
console.log(items); //Logs ["<li class="0">Click Me</li>", "<li class="1">Click Me Too</li>"]
for(var index in items) {
console.log(items[index]); //does not log
console.log("HELLO"); //does not log
}
}
I can’t see a reason why I can’t loop through that. I have tried $(items).each(function() as well and nothing will output. Any ideas? Here is how that items object gets built…
setButtons: function(type) {
var that = this;
var items = [];
$.getJSON("button_list.php?type=" + type, function(data) {
$.each(data.buttons, function(key, val) {
console.log(items);
items.push("<li class='" + key + "'>" + val + "</li>");
});
console.log(items);
});
that.buttons = items;
},
You’re using
for inon an array which doesn’t have properties to be assigned toindexas if you were iterating over an object literal.Replace with this: