所以我从所有名单中得到了所有名单中的所有牌:
var url3 = "https://api.trello.com/1/lists/"+listId+"/cards?key="+key+"&token="+token;
现在我需要以某种方式加入电路板列表并根据电路板ID获取每张卡的电路板名称,我不知道如何......
这是我的整个功能,试图获得截止日期的所有卡片,但我也希望获得每张卡片所在的电路板名称...
function getDues(listId){
var xmlhttp3 = new XMLHttpRequest();
var url3 = "https://api.trello.com/1/lists/"+listId+"/cards?key="+key+"&token="+token;
xmlhttp3.onreadystatechange = function() {
if(xmlhttp3.readyState == 4 && xmlhttp3.status == 200) {
var arrCards = JSON.parse(xmlhttp3.responseText);
var dueName = "";
var dueDate = "";
var board = "";
for(c = 0; c < arrCards.length; c++){
if(arrCards[c].due !== null){
var dueName = arrCards[c].name;
var dueDate = arrCards[c].due;
var boardNo = arrCards[c].idBoard;
var date = new Date(dueDate);
var deadline = "";
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var now = new Date();
var result = "https://api.trello.com/1/organizations/"+orgId+"/boards?key="+key+"&token="+token;
for (card in arrCards) {
if (!arrCards.hasOwnProperty(card)) { continue; }
var name = result.name;
card.boardName = name
console.log(card.boardName);
}
}
}
}
}
xmlhttp3.open("GET", url3, true);
xmlhttp3.send();
}
我获得的所有董事会名称都是“未定义”。
更新
改变了我获得卡片的方式,并且这样可行:
function getDues(boardId) {
var xmlhttp3 = new XMLHttpRequest();
var url3 = "https://api.trello.com/1/boards/"+boardId+"/cards?key="+key+"&token="+token;
xmlhttp3.onreadystatechange = function() {
if (xmlhttp3.readyState === 4 && xmlhttp3.status === 200) {
var arrCards = JSON.parse(xmlhttp3.responseText);
var dueName = "";
var dueDate = "";
var board = "";
for (var c = 0; c < arrCards.length; c++) {
if (arrCards[c].due !== null) {
var dueName = arrCards[c].name; // due card name
var dueDate = arrCards[c].due; // due date
var boardNo = arrCards[c].idBoard; // board id
var date = new Date(dueDate);
var deadline = "";
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var now = new Date();
var xmlhttpBoardName = new XMLHttpRequest();
var boardNameUrl = "https://api.trello.com/1/boards/" + boardNo + "/?key=" + key + "&token=" + token;
xmlhttpBoardName.onreadystatechange = function() {
if (xmlhttpBoardName.readyState === 4 && xmlhttpBoardName.status === 200) {
var board = JSON.parse(xmlhttpBoardName.responseText);
var boardName = board.name; // board name
}
}
xmlhttpBoardName.open("GET", boardNameUrl, true);
xmlhttpBoardName.send();
}
}
}
}
xmlhttp3.open("GET", url3, true);
xmlhttp3.send();
}
答案 0 :(得分:1)
基于你的代码,这样的东西应该有效:
function getDues(listId) {
var xmlhttp3 = new XMLHttpRequest();
var url3 = "https://api.trello.com/1/lists/"+listId+"/cards?key="+key+"&token="+token;
xmlhttp3.onreadystatechange = function() {
if (xmlhttp3.readyState === 4 && xmlhttp3.status === 200) {
var arrCards = JSON.parse(xmlhttp3.responseText);
var dueName = "";
var dueDate = "";
var board = "";
for (var c = 0; c < arrCards.length; c++) {
if (arrCards[c].due !== null) {
var dueName = arrCards[c].name;
var dueDate = arrCards[c].due;
var boardNo = arrCards[c].idBoard;
var date = new Date(dueDate);
var deadline = "";
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var now = new Date();
var xmlhttpBoardName = new XMLHttpRequest();
var boardNameUrl = "https://api.trello.com/1/boards/" + boardNo + "/?key=" + key + "&token=" + token;
xmlhttpBoardName.onreadystatechange = function() {
if (xmlhttpBoardName.readyState === 4 && xmlhttpBoardName.status === 200) {
var board = JSON.parse(xmlhttpBoardName.responseText);
var boardName = board.name; // HERE YOU HAVE YOUR BOARD NAME
console.log(boardName);
}
}
xmlhttpBoardName.open("GET", boardNameUrl, true);
xmlhttpBoardName.send();
}
}
}
}
xmlhttp3.open("GET", url3, true);
xmlhttp3.send();
}
无论如何,我建议你使用official library,你不必处理所有的http请求。