我正在构建一个应用程序,显示每个Trello董事会的进度,作为核对表项目的总数与已完成的核对表项目数量的比较。我可以单独为每个电路板执行此操作,但无法弄清楚如何显示电路板的总数。
我想我需要的主要是如何在通过卡片.each循环时区分每个板。一旦我获得该板的所有核对清单项目,我需要对该数据做一些事情,然后转到下一个板。
这是我到目前为止的代码:
Trello.members.get("me", function (member) {
var memberID = member.id;
Trello.get("members/" + memberID + "/boards", function (boards) {
$.each(boards, function (index, board) {
var boardName = board.name,
boardID = board.shortLink;
var boardLi = $('<li>', {
class: 'boardCard'
}).appendTo($trelloBoards);
var titleHeader = $('<div>', {
class: 'boardHeader',
html: '<h3>' + boardName + '</h3>'
}).appendTo(boardLi);
var progressBar = $('<progress>', {
value: 10,
max: 100,
class: 'boardProgress'
}).appendTo(boardLi);
//get all the cards for a specific board
Trello.get("boards/" + boardID + "/cards", function (cards) {
$.each(cards, function (index, card) {
var boardItemsChecked = card.badges.checkItemsChecked,
boardTotalItems = card.badges.checkItems;
//here I need to display the total number of complete
// and incomplete checklist tasks for each board
});
});
这是我能够得到的最接近的。它显示了多个进度条(每个卡都存在于板上)。问题是我需要检查董事会的所有checkItem:
Trello.get("boards/" + boardID + "/cards", function(cards) {
$.each(cards, function(ix, card) {
var checked = card.badges.checkItemsChecked,
totalChecks = card.badges.checkItems;
var totalChecked = 0;
totalChecked = totalChecked + checked;
var sumTotalChecks = 0;
sumTotalChecks = sumTotalChecks + totalChecks;
var progressBar = $('<progress>', {
value: totalChecked,
max: sumTotalChecks,
class: 'boardProgress'
}).appendTo(titleHeader);
});
});
答案 0 :(得分:0)
以下是解决方案:
Trello.get("boards/" + boardID + "/cards", function(cards) {
var totalChecked = 0,
totalExisting = 0;
$.each(cards, function(ix, card) {
var checked = card.badges.checkItemsChecked,
totalChecks = card.badges.checkItems;
totalChecked += checked;
totalExisting += totalChecks;
$('progress' + "#" + boardID).attr({
value: totalChecked,
max: totalExisting
});
});
});