0
var boardIdGlobal =[boardid1,boardid2];
var boardIdGlobalTemp, urlChecklistsGlobal, urlListsGlobal;
contactStatusGlobalArray = [];
function checklistStatus(){
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
            var checklist = JSON.parse(xmlhttp.responseText);
            for(i=0;i<checklist.length;i++){
                for(t=0;t<checklist[i].cards.length;t++){
                    for(x=0;x<checklist[i].checkItems.length;x++){
                        if(checklist[i].checkItems[x].name.search("Contact")===0){
                            contactStatusGlobalArray.push(["unknown",checklist[i].cards[t].idList,checklist[i].checkItems[x].name,checklist[i].checkItems[x].state]);
                        }   
                    }
                }
            };
        };
    };
    xmlhttp.open("GET", urlChecklistsGlobal, true);
    xmlhttp.send();
    console.log(contactStatusGlobalArray);
}

function init(){
    for(i=0;i<boardIdGlobal.length;i++){
        boardIdGlobalTemp = boardIdGlobal[i];
        urlChecklistsGlobal = "https://api.trello.com/1/boards/" + boardIdGlobalTemp + "/checklists?cards=open&card_fields=idList&key=[key]&token=[token]"
        urlListsGlobal = "https://api.trello.com/1/boards/" + boardIdGlobalTemp + "/lists?key=[key]&token=[token]"
        checklistStatus();
    }
};
window.onload = init;

I'm using the Trello API to find the checklist status, the checklist item name, and the list id. I'm trying to push each instance of the data to a global array, to get Array [Array1, Array[8]...] etc. The console for this code logs:

Click to view image of how the .push method worked

I need to be able to loop through the global array again, but after I use .push, and try to get the length of my global array, I get a length of 0. I tried pushing objects with the same result: it looks like the .push works but that it's pushing to the same index.

How do I fix this so I get an Array of arrays (or an array of objects) that I can loop through again? I am very much a beginner so feedback is appreciated.

saranes
  • 1
  • 1
  • Offtop: Why dont you just use ajax libraries instead of this spaghetti – Medet Tleukabiluly Feb 10 '16 at 20:22
  • @MedetTleukabiluly: His "spaghetti" doesn't have anything to do with the XHR request. No need for libraries for these simple operations. –  Feb 10 '16 at 20:26
  • @squint well, maybe, i just saw the url `https://api.trello.com/1/boards/` and instantly tho that maybe it's not single case when he would use ajax – Medet Tleukabiluly Feb 10 '16 at 20:32
  • @squint Thanks for linking to the duplicate question – saranes Feb 10 '16 at 20:48
  • @saranes: You're welcome. Everyone runs into this issue sooner or later. The linked answers give a very thorough overview of the problem and solutions. –  Feb 10 '16 at 23:20

0 Answers0