最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get the card created date from the Trello API? - Stack Overflow

programmeradmin6浏览0评论

I am trying to get the date each card was created via the Trello API. In JSFiddle, I've used the test code from the Trello site, and am trying to add an alert to each card so when clicked it shows the user the created date of the card.

I don't think I have the syntax right, however:

$.each(cards, function(ix, card) {
                $("<a>")
                .addClass("card")
                .text(card.name)
                .appendTo($cards)
                .click(function(){
                   alert(Trello.get("cards/" + card.id + "?action=createCard", { fields: "date" }));
                })

The JSFiddle is here: /

I'm also not too sure what it should be returning which is making it tricky to debug. How do I access the object it returns?

I am trying to get the date each card was created via the Trello API. In JSFiddle, I've used the test code from the Trello site, and am trying to add an alert to each card so when clicked it shows the user the created date of the card.

I don't think I have the syntax right, however:

$.each(cards, function(ix, card) {
                $("<a>")
                .addClass("card")
                .text(card.name)
                .appendTo($cards)
                .click(function(){
                   alert(Trello.get("cards/" + card.id + "?action=createCard", { fields: "date" }));
                })

The JSFiddle is here: http://jsfiddle/bdgriffiths/E4rLn/392/

I'm also not too sure what it should be returning which is making it tricky to debug. How do I access the object it returns?

Share Improve this question asked Nov 17, 2013 at 10:23 BenBen 4,3199 gold badges69 silver badges105 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Finally found an answer to this - the card created date is embedded in the card id!

How to get the time a card was created

Trello.get is an asynchronous function. This is necessary, because it uses AJAX, which is asynchronous. This means that you need to pass it a callback; its return value is essentially meaningless. Changing your code to:

$.each(cards, function(ix, card) {
    $("<a>")
    .addClass("card")
    .text(card.name)
    .appendTo($cards)
    .click(function(){
       Trello.get("cards/" + card.id + "?action=createCard", { fields: "date" }, function(card) {
         alert(card);
       });
    })

should fix it.

发布评论

评论列表(0)

  1. 暂无评论