2015-11-04 58 views
-3

如何獲取有多少卡在Trello中有一個列表並顯示在網站的某個頁面上? 有可能嗎?Trello卡顯示在網頁上的金額

欲例如:

--------我的網頁---------

TO-DO:2 做:5 DONE:10

+2

嗨,歡迎來到stackoverflow,你可以顯示一些你已經做的嘗試?有一個閱讀這裏也:http://stackoverflow.com/help/how-to-ask – Pogrindis

+0

但我不知道該怎麼做,所以我想知道如果這是可能的,我應該從哪裏開始。 –

+1

@ marcelo-junior這裏的另一個規範是選擇一個答案來回答你的問題。我已發佈回答你的問題。如果這些答案不符合您的需求,請選擇其中一個或另一個,或詢問提煉問題。 –

回答

1

下面是一個JavaScript方法,你可以在瀏覽器的控制檯嘗試:

$ trello_JSON = jQuery.get("https://trello.com/1/boards/5WWgH1bB/lists").responseJSON 
Object {readyState: 1} 
$ trello_JSON = trello_response.responseJSON 
[Object, Object, Object] 
$ trello_list_to_do = jQuery.get('https://trello.com/1/lists/'+trello_JSON[0]['id']+'/cards') 
Object {readyState: 1} 
$ trello_list_doing = jQuery.get('https://trello.com/1/lists/'+trello_JSON[1]['id']+'/cards') 
Object {readyState: 1} 
$ trello_list_done = jQuery.get('https://trello.com/1/lists/'+trello_JSON[2]['id']+'/cards') 
Object {readyState: 1} 
$ to_do_size = trello_list_to_do.responseJSON.length 
3 
$ doing_size = trello_list_doing.responseJSON.length 
2 
$ done_size = trello_list_done.responseJSON.length 
4 

現在讓我們假設您有相關的類「內容」的網頁div,你想你的計數添加到該第一段DIV。

$ paragraphs = document.querySelectorAll(".content p") 

會給你一個該div中所有段落的數組。現在我們將結果添加到該段的末尾。

$ paragraphs[0].innerHTML = paragraphs[0].innerHTML + "<b /r><br />TO DO: " + to_do_size + " DOING: " + doing_size + " DONE: " + done_size 
1

從它的網址獲取你的主板的短鏈接。對於我的主板https://trello.com/b/5WWgH1bB/tasks,短鏈接是5WWgH1bB

您可以使用下面的API請求查詢單板:

$ curl https://trello.com/1/boards/5WWgH1bB/lists 

這將返回:

[{"id":"563e21ae7f01e6bb5334306d", 
    "name":"To Do", 
    "closed":false, 
    "idBoard":"563e20b4b8580872c2b1b469", 
    "pos":65535, 
    "subscribed":null}, 
    {"id":"563e21b0e4572f932855c1d8", 
    "name":"Done", 
    "closed":false, 
    "idBoard":"563e20b4b8580872c2b1b469", 
    "pos":131071, 
    "subscribed":null}, 
    {"id":"563e21b171ba02aa1f3c67be", 
    "name":"Doing", 
    "closed":false, 
    "idBoard":"563e20b4b8580872c2b1b469", 
    "pos":196607, 
    "subscribed":null}] 

想我的手這個JSON一些編程語言,就像說的紅寶石,這樣

require 'json' 
trello_response = '[{"id":"563e21ae7f01e6bb5334306d","name":"To Do","closed":false,"idBoard":"563e20b4b8580872c2b1b469","pos":65535,"subscribed":null},{"id":"563e21b0e4572f932855c1d8","name":"Done","closed":false,"idBoard":"563e20b4b8580872c2b1b469","pos":131071,"subscribed":null},{"id":"563e21b171ba02aa1f3c67be","name":"Doing","closed":false,"idBoard":"563e20b4b8580872c2b1b469","pos":196607,"subscribed":null}]' 
trello_hash = JSON.parse(trello_response) 
trello_hash.each {|i| puts "#{i['name']}, #{i['id']}" } 

這會給我

To Do, 563e21ae7f01e6bb5334306d 
Done, 563e21b0e4572f932855c1d8 
Doing, 563e21b171ba02aa1f3c67be 

這些是我的電路板上每個列表相關的唯一ID。我可以反過來查詢這些。

$ curl https://trello.com/1/lists/563e21ae7f01e6bb5334306d/cards 
$ curl https://trello.com/1/lists/563e21b0e4572f932855c1d8/cards 
$ curl https://trello.com/1/lists/563e20b4b8580872c2b1b469/cards 

這些請求中的每一個與返回的每個名單上的細節的大型JSON斑點。

假設我將這些文件逐一遞交給Ruby。

hash.size 

你可以這樣顯示這些值:

puts "TO-DO: #{hash_to_do.size} DOING: #{hash_doing.size} DONE: #{hash_done.size}" 

list_to_do = '[{"id":"563e21b5f666242dd2934377","checkItemStates":[],"closed":false,"dateLastActivity":"2015-11-07T16:07:17.423Z","desc":"","descData":null,"idBoard":"563e20b4b8580872c2b1b469","idList":"563e21ae7f01e6bb5334306d","idMembersVoted":[],"idShort":1,"idAttachmentCover":null,"manualCoverAttachment":false,"idLabels":[],"name":"task 1","pos":65535,"shortLink":"9xU5xLYI","badges":{"votes":0,"viewingMemberVoted":false,"subscribed":false,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"comments":0,"attachments":0,"description":false,"due":null},"due":null,"idChecklists":[],"idMembers":[],"labels":[],"shortUrl":"https://trello.com/c/9xU5xLYI","subscribed":false,"url":"https://trello.com/c/9xU5xLYI/1-task-1"},{"id":"563e21b744fb22f201b747ab","checkItemStates":[],"closed":false,"dateLastActivity":"2015-11-07T16:07:19.095Z","desc":"","descData":null,"idBoard":"563e20b4b8580872c2b1b469","idList":"563e21ae7f01e6bb5334306d","idMembersVoted":[],"idShort":2,"idAttachmentCover":null,"manualCoverAttachment":false,"idLabels":[],"name":"task 2","pos":131071,"shortLink":"admRw9X0","badges":{"votes":0,"viewingMemberVoted":false,"subscribed":false,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"comments":0,"attachments":0,"description":false,"due":null},"due":null,"idChecklists":[],"idMembers":[],"labels":[],"shortUrl":"https://trello.com/c/admRw9X0","subscribed":false,"url":"https://trello.com/c/admRw9X0/2-task-2"},{"id":"563e21b84d1f7ed445c6469e","checkItemStates":[],"closed":false,"dateLastActivity":"2015-11-07T16:07:20.961Z","desc":"","descData":null,"idBoard":"563e20b4b8580872c2b1b469","idList":"563e21ae7f01e6bb5334306d","idMembersVoted":[],"idShort":3,"idAttachmentCover":null,"manualCoverAttachment":false,"idLabels":[],"name":"task 3","pos":196607,"shortLink":"ZNfOzI2j","badges":{"votes":0,"viewingMemberVoted":false,"subscribed":false,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"comments":0,"attachments":0,"description":false,"due":null},"due":null,"idChecklists":[],"idMembers":[],"labels":[],"shortUrl":"https://trello.com/c/ZNfOzI2j","subscribed":false,"url":"https://trello.com/c/ZNfOzI2j/3-task-3"}]' 
list_done = '[{"id":"563e21bc36407537591b88f1","checkItemStates":[],"closed":false,"dateLastActivity":"2015-11-07T16:07:24.364Z","desc":"","descData":null,"idBoard":"563e20b4b8580872c2b1b469","idList":"563e21b0e4572f932855c1d8","idMembersVoted":[],"idShort":4,"idAttachmentCover":null,"manualCoverAttachment":false,"idLabels":[],"name":"task 4","pos":65535,"shortLink":"y2Px7aED","badges":{"votes":0,"viewingMemberVoted":false,"subscribed":false,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"comments":0,"attachments":0,"description":false,"due":null},"due":null,"idChecklists":[],"idMembers":[],"labels":[],"shortUrl":"https://trello.com/c/y2Px7aED","subscribed":false,"url":"https://trello.com/c/y2Px7aED/4-task-4"},{"id":"563e21bea7e6e1c41f2048ac","checkItemStates":[],"closed":false,"dateLastActivity":"2015-11-07T16:07:26.376Z","desc":"","descData":null,"idBoard":"563e20b4b8580872c2b1b469","idList":"563e21b0e4572f932855c1d8","idMembersVoted":[],"idShort":5,"idAttachmentCover":null,"manualCoverAttachment":false,"idLabels":[],"name":"task 5","pos":131071,"shortLink":"6cGvweyp","badges":{"votes":0,"viewingMemberVoted":false,"subscribed":false,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"comments":0,"attachments":0,"description":false,"due":null},"due":null,"idChecklists":[],"idMembers":[],"labels":[],"shortUrl":"https://trello.com/c/6cGvweyp","subscribed":false,"url":"https://trello.com/c/6cGvweyp/5-task-5"}]' 
list_doing = '[{"id":"563e21c0e4572f932855c201","checkItemStates":[],"closed":false,"dateLastActivity":"2015-11-07T16:07:28.775Z","desc":"","descData":null,"idBoard":"563e20b4b8580872c2b1b469","idList":"563e21b171ba02aa1f3c67be","idMembersVoted":[],"idShort":6,"idAttachmentCover":null,"manualCoverAttachment":false,"idLabels":[],"name":"task 6","pos":65535,"shortLink":"dy3bByst","badges":{"votes":0,"viewingMemberVoted":false,"subscribed":false,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"comments":0,"attachments":0,"description":false,"due":null},"due":null,"idChecklists":[],"idMembers":[],"labels":[],"shortUrl":"https://trello.com/c/dy3bByst","subscribed":false,"url":"https://trello.com/c/dy3bByst/6-task-6"},{"id":"563e21c2e200c94a546dd4bf","checkItemStates":[],"closed":false,"dateLastActivity":"2015-11-07T16:07:30.399Z","desc":"","descData":null,"idBoard":"563e20b4b8580872c2b1b469","idList":"563e21b171ba02aa1f3c67be","idMembersVoted":[],"idShort":7,"idAttachmentCover":null,"manualCoverAttachment":false,"idLabels":[],"name":"task 7","pos":131071,"shortLink":"qVF7Z2sx","badges":{"votes":0,"viewingMemberVoted":false,"subscribed":false,"fogbugz":"","checkItems":0,"checkItemsChecked":0,"comments":0,"attachments":0,"description":false,"due":null},"due":null,"idChecklists":[],"idMembers":[],"labels":[],"shortUrl":"https://trello.com/c/qVF7Z2sx","subscribed":false,"url":"https://trello.com/c/qVF7Z2sx/7-task-7"}]' 
hash_to_do = JSON.parse(list_to_do) 
hash_done = JSON.parse(list_done) 
hash_doing = JSON.parse(list_doing) 

然後你可以通過你所創建的哈希值的大小得到的每個列表上牌數

哪給出

TO-DO: 3 DOING: 2 DONE: 2