So I’m looping through a set of JSON arrays, and then looping through each individual array.
If I remove the two if statements it will loop through both data sets and append the ‘target’ with both ‘data’ sets, but like it is now, it will only append the items.join through the first each loop.
The case stuff was an if loop first, thinking it would matter, but no.
Strange thing is, the consoleOut (like console.log) does print my stuff, so It actually does loop through both arrays within the JSON set.
$.each(data, function(keys, vals)
{
var items = [];
$.each(data[keys], function(key, val)
{
var currString = JSON.stringify(val);
switch (key)
{
case "ID":
consoleOut("ID: "+currString+" loaded");
break;
case "parentIDs":
consoleOut("parentIDs: "+currString);
break;
case "UID":
consoleOut("UID: "+currString);
UID = unquote(currString);
break;
case "title":
consoleOut("Title: "+currString);
items.push('<H1 class="' + key + '">' + unquote(currString) + '</H1>');
break;
case "img":
consoleOut("IMG: "+currString);
if ($(currString).val() !== '')
{
items.push('<IMG class="' + key + '" src='+currString+'></IMG>');
};
break;
case "text":
consoleOut("TXT: "+currString);
if ($(currString).val() !== '')
{
items.push('<P class="' + key + '">'+currString+'</P>');
};
break;
}
});
consoleOut("---------");
$('<DIV/>', {
'id': UID,
html: items.join('')
}).appendTo(target);
}
)
I’m wondering how the if statements are breaking my appending to the main ‘items’ array..
(When I don’t stringify the val at the beginning it will loop, but that’s because the if statements are then true, but stop working when false.. So maybe It’s better to modify my if statement for that, but I’m still puzzled as to how the .push stops working?)
It is saying you are making an element and looking at the value attribute of that element. Is that what you really want? I do not think image or text has a value.
I would think you would want to use length or html()
[EDIT] Looking at your object, you just want to check the lenght of currString