如何获取Trello中有多少张牌列表并在网站的页面上显示? 有可能吗?
我想要例如:
--------我的网页---------
待办事项:2 做:5 完成:10
答案 0 :(得分: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交给某些编程语言,比如Ruby,就像这样
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 blob,其中包含每个列表中卡的详细信息。
假设我一个接一个地将它们交给Ruby。
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)
然后你可以通过获取你创建的哈希的大小来获得每个列表上的卡数:
hash.size
您可以这样显示这些值:
puts "TO-DO: #{hash_to_do.size} DOING: #{hash_doing.size} DONE: #{hash_done.size}"
给出了
TO-DO: 3 DOING: 2 DONE: 2
答案 1 :(得分: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