我试图在高级别执行以下操作:
我理解事物的方式是我需要执行getJSON调用,让它完成,然后在其上执行另一个getJSON。我已经环顾四周并了解$ .when()函数可能有所帮助,但我似乎无法远程完成这项工作。
我认为当getJSON返回一个未定义的对象时可能会出现问题,但我不确定如何跳过这些对象。任何帮助都将非常感激!
cardIDapiCall = "https://api.trello.com/1/boards/" + boardID + "/cards?fields=id&key=" + appKey + "&token=" + tokenKey;
$.getJSON(cardIDapiCall, function(cardID) {
var cardID_tableData = [];
// Iterate over the JSON object
for (var i = 0, len = cardID.length; i < len; i++) {
cardID_tableData.push({
"card_id": cardID[i].id,
});
}
//get action data
for (var j = 1, len = cardID_tableData.length; j < len; j++) {
//this alert works
alert("card id: " + cardID_tableData[j].card_id);
var actionapiCall = "https://api.trello.com/1/cards/" + cardID_tableData[j].card_id + "/actions?key=" + appKey + "&token=" + tokenKey;
//why isn't this getting called???
$.getJSON(actionapiCall, function() {
//this alert doesn't work
alert("action call successful");
});
var action_tableData = [];
action_tableData.push({
"action_id": action[j].id,
"action_type": action[j].type,
})
table.appendRows(action_tableData);
doneCallback();
}
});