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 badges2 Answers
Reset to default 5Finally 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.