I'm having a couple of (hopefully small) issues with this fiddle
http://jsfiddle.net/gq0t4j93/22/
The functionality is working but my logic has gotten messed up along the way.
I'm nesting arrays of 'content' within a main array for the 'pageID'. The issue is that for HTML rendering, i need to first look at the page_type_id of the first 'page' element and then look at the panel_type_id of the content element.
My first problem is that my forloop at line 107 seems to only access odd number pageIDs but if I remove it it will access all of them.
But the other real issue is that At line 109, I want to change
if (currentJSONobject.content.length >= 1) {
leftContent.innerHTML = currentJSONobject.content[i].content;
}
if (currentJSONobject.content.length >= 2) {
rightContent.innerHTML = currentJSONobject.content[i].content;
} else {
rightContent.innerHTML = '';
}
To instead use page_type_id and panel_type_id instead of length, so:
if (currentJSONobject.page_type_id == 2) {
fullColumn.style.display = "none";
if (currentJSONobject.content.panel_type_id == 2) {
leftContent.innerHTML = currentJSONobject.content[i].content;
}
if (currentJSONobject.content.panel_type_id == 3) {
rightContent.innerHTML = currentJSONobject.content[i].content;
}
}
It seems simple but I can't figure out how to actually change it that way.
Again, it's cycling correctly and showing the content but I need to be able to evolve the logic for several page and panel types, hopefully someone can see where I'm going wrong here
UPDATE:
Switching from ternary in accepted answer to if/else
for(var i = 0; i < currentJSONobject.content.length; i++){
fullContent.innerHTML = '';
rightContent.innerHTML = '';
leftContent.innerHTML = '';
topLeftContent = '';
topRightContent = '';
bottomLeftContent = '';
bottomRightContent = '';
if(currentJSONobject.content[i].page_type_id == 1){
leftColumn.style.display = "none";
rightColumn.style.display = "none";
leftColumnQtr.style.display = "none";
rightColumnQtrHalf.style.display = "none";
rightColumnQtr.style.display = "none";
leftColumnQtrHalf.style.display = "none";
if(currentJSONobject.content[i].panel_type_id == 1){
fullContent.innerHTML = currentJSONobject.content[i].content;
}
}else if(currentJSONobject.content[i].page_type_id == 2){
fullColumn.style.display = "none";
leftColumnQtr.style.display = "none";
rightColumnQtrHalf.style.display = "none";
rightColumnQtr.style.display = "none";
leftColumnQtrHalf.style.display = "none";
if(currentJSONobject.content[i].panel_type_id == 2){
leftContent.innerHTML = currentJSONobject.content[i].content;
} if(currentJSONobject.content[i].panel_type_id == 3){
rightContent.innerHTML = currentJSONobject.content[i].content;
}
}
// fullContent.innerHTML = '';
// rightContent.innerHTML = '';
// leftContent.innerHTML = '';
// fullContent.innerHTML = currentJSONobject.content[i].panel_type_id == 1 ? currentJSONobject.content[i].content : fullContent.innerHTML;
// leftContent.innerHTML = currentJSONobject.content[i].panel_type_id == 2 ? currentJSONobject.content[i].content : leftContent.innerHTML;
// rightContent.innerHTML = currentJSONobject.content[i].panel_type_id == 3 ? currentJSONobject.content[i].content : rightContent.innerHTML;
}
original_jsonhas two objects with the same pageID."pageID": "93".