2013-07-24 45 views
3

我想返回基於用戶從下拉選擇菜單中選擇的板卡列表。獲取基於板卡的列表 - Trello API

DEMOhttp://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); 
     }); 
    }); 

我不知道如何根據選擇下拉菜單顯示卡?

DEMOhttp://jsfiddle.net/nNesx/1378/

回答

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

然後你可以gr ab所有卡片僅適用於該主板

var resource = "boards/" . $("#boards").val() . "/cards"; 
Trello.get(resource, function(cards) { 
    // rest of code... 
});