Trello API - 将卡片与板连接以根据板 id 获取板名称
Trello API - connect cards with boards to get board name based on the board id
所以我得到了所有列表中的所有卡片,在我的所有板中:
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();
}
我得到的板名是 "undefined"。
更新
改变了我获得卡片的方式,这样就可以了:
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();
}
根据您的代码,这样的事情应该可行:
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请求。
所以我得到了所有列表中的所有卡片,在我的所有板中:
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();
}
我得到的板名是 "undefined"。
更新
改变了我获得卡片的方式,这样就可以了:
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();
}
根据您的代码,这样的事情应该可行:
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请求。