3

ユーザーがドロップダウン選択メニューから選択したボードに基づいてカードのリストを返そうとしています。

デモ http://jsfiddle.net/nNesx/1378/

次のようにボードのリストを作成しました

var $boards = $("<select>")
        .text("Loading Boards...")
        .appendTo("#output");

    // Output a list of all of the boards that the member 
    // is assigned to
    Trello.get("members/me/boards", function(boards) {
        $boards.empty();
        $.each(boards, function(ix, board) {
            $("<option>")
            .attr({href: board.url, target: "trello"})
            .addClass("board")
            .text(board.name)
            .appendTo($boards);
        });  
    });

これにより、利用可能なすべてのボードをドロップダウンで選択できます。

ユーザーがボードを選択したら、そのボードのカードを表示します。このコードをカードに使用していますが、すべてのカードが表示されます。

var $cards = $("<div>")
        .text("Loading Boards...")
        .appendTo("#outputCards");

    // Output a list of all of the boards that the member 
    // is assigned to based on what they choose in select dropdown
    Trello.get("members/me/cards", function(cards) {
        $cards.empty();
        $.each(cards, function(ix, card) {
            $("<a>")
            .attr({href: card.url, target: "trello"})
            .addClass("card")
            .text(card.name)
            .appendTo($cards);
        });  
    });

選択ドロップダウンに基づいてカードを表示する方法がわかりません。

デモ http://jsfiddle.net/nNesx/1378/

4

1 に答える 1

8

別のリソースを使用する必要があります

members/me/cardsを使用する代わりに、boards/[board_id]/cards

選択にIDを追加し、各オプションにボードIDを追加するだけです...

var $boards = $("<select>")
        .attr("id", "boards") /* we'll use this later */
        .text("Loading Boards...")
        .appendTo("#output");

     $("<option>")
      /* notice the added board id value */
      .attr({href: board.url, target: "trello", value : board.id})
      .addClass("board")
      .text(board.name)
      .appendTo($boards);

そして、そのボードだけのすべてのカードを取得できます

var resource = "boards/" . $("#boards").val() . "/cards";
Trello.get(resource, function(cards) {
  // rest of code...
});
于 2013-07-29T20:52:26.800 に答える