0

现场页面可以在这里看到

我的目标是根据它出现的列表将特定类应用于第二个 UL 中的每个列表项。第二个 json 调用返回一个与第一个列表中的 ID 和名称对匹配的 ID。

我想将每个 listID 分配给一个名为 $listID 的 $variable,其值是该列表的名称。

例如$514fc8993f53cfb366006851 = "To Do";

然后,我可以使用 if 语句根据 PHP 第二个块中的一系列 if 语句来分配一个类。

任何生成这些变量的帮助将不胜感激。

相关代码如下:

<p>The sample board contains the following lists:</p>
<ul>
    <?
        $lists_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/lists?key=9ee57574e9f968cedf9ac9964d2f7c4e");
        $lists = json_decode($lists_enc, true);
        $testing = array();

        foreach ($lists as $list) {
            $id = $list["id"];
            $name = $list["name"];

            echo "<li>".$name." (".$id.")</li>\n";
        }
        echo "</ul>";
    ?>

<p>The sample board contains the following cards:</p>
<ul>
    <?
        $cards_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/cards?fields=name,idList&key=9ee57574e9f968cedf9ac9964d2f7c4e");      
        $cards = json_decode($cards_enc, true);

        foreach ($cards as $card) {
        echo "<li class=".$status.">".$card["name"]."</li>\n";
      }  

    ?>
</ul>
4

2 回答 2

1
<?php
//Reference the trello API's
$lists_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/lists?key=9ee57574e9f968cedf9ac9964d2f7c4e");
$lists = json_decode($lists_enc, true);
$cards_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/cards?fields=name,idList&key=9ee57574e9f968cedf9ac9964d2f7c4e");      
$cards = json_decode($cards_enc, true);
//Go through every card
foreach ($cards as $card) {
    $idCard = $card['id'];

    //Go through all lists
    foreach ($lists as $list) {
        $idList = $list['id'];

        //If card is related to list, then create an associative variable
        //with the id of list
        if ($card['id'] == $list['id'] {
            $idList[$idList][] = $idCard;
        }
    }
    //gone through all lists
}
//-- gone through all cards
?>

现在您将拥有 $idList[514fc8993f53cfb366006851]、$idList[514fc8993f53cfb366006852] 和 $idList[514fc8993f53cfb366006853] 之类的东西,它们应该包含与列表相关的卡片。虽然我没有测试代码,但我希望你能得到图片......

于 2013-03-25T07:22:33.797 回答
0
<?
  // Create array $convert[] to allow translation of listID into listName
    for ($i=0; $i < count($lists); $i++) { 
      $convert[$lists[$i][id]]=$lists[$i][name];
    }

  // iterate over all cards, create list item for each with class that has a slug equivalent of the list name  
    foreach ($cards as $card) {
       $id = $card[idList];
       echo "<li class=".slug($convert[$id]).">".$card["name"]."</li>\n";
    }  

?>
于 2013-03-27T04:32:41.417 回答