1

我正在构建一个应用程序,将每个 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  

                });
            });

这是我能得到的最接近的。它显示了多个进度条(对于板上存在的每张卡一个进度条)。问题是我需要对董事会的所有 checkItems 进行总检查:

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);
                });
            });
4

1 回答 1

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
                        });
                });
            });
于 2014-02-11T00:50:35.787 回答