【问题标题】:How do I get the card created date from the Trello API?如何从 Trello API 获取卡片创建日期?
【发布时间】:2013-11-17 10:23:38
【问题描述】:

我正在尝试通过 Trello API 获取每张卡片的创建日期。在 JSFiddle 中,我使用了 Trello 站点的测试代码,并尝试向每张卡片添加警报,以便在单击时向用户显示卡片的创建日期。

但是,我认为我的语法不正确:

$.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" }));
                })

JSFiddle 在这里:http://jsfiddle.net/bdgriffiths/E4rLn/392/

我也不太确定它应该返回什么,这使得调试变得很棘手。如何访问它返回的对象?

【问题讨论】:

    标签: javascript api get trello


    【解决方案1】:

    终于找到了答案 - 卡片创建日期嵌入在卡片 ID 中!

    How to get the time a card was created

    【讨论】:

      【解决方案2】:

      Trello.get 是一个异步函数。这是必要的,因为它使用异步的 AJAX。这意味着您需要向它传递一个回调;它的返回值本质上是没有意义的。将您的代码更改为:

      $.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);
             });
          })
      

      应该修复它。

      【讨论】:

      • 谢谢亚伦。我仍然收到显示 [object Object] 的警报。我需要做其他事情才能访问日期吗?
      • @Ben 正如我的代码所暗示的,您正在提醒card。检查对象可能是个好主意,但card.actions[0] 会更接近您要查找的内容。
      猜你喜欢
      • 2014-02-02
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 2012-05-01
      • 2020-10-20
      • 2014-10-30
      • 2015-07-10
      • 2017-10-07
      相关资源
      最近更新 更多