简体   繁体   中英

How do I get the card created date from the Trello API?

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.net/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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM