简体   繁体   English

使用Javascript通过API更改Trello上卡的名称

[英]Change name of card on Trello with API by Javascript

I have this code in Javascript to modify the name of a Trello card through its API, and I do not get it, any ideas? 我在Javascript中有这段代码可以通过Trello卡的API修改其名称,但我不明白,有什么想法吗?

Documentation API Trello: https://developers.trello.com/v1.0/reference#cardsid-1 文档API Trello: https : //developers.trello.com/v1.0/reference#cardsid-1

Code: 码:

var onAuthorize = function() {
    updateLoggedIn();
    $("#output").empty();

    Trello.members.get("me", function(member){
        $("#fullName").text(member.fullName);

    var id= "5ab7c3c631a2019c50b701c8";
//Change name
         Trello.put('/boards/me/cards/5ab7c3c631a2019c50b701c8/name?value=nombrecito',function () {alert("funciona bien")}, function(err) {alert( "mal")});

    });

    };


var updateLoggedIn = function() {
    var isLoggedIn = Trello.authorized();
    $("#loggedout").toggle(!isLoggedIn);
    $("#loggedin").toggle(isLoggedIn);        
};

var logout = function() {
    Trello.deauthorize();
    updateLoggedIn();
};

Trello.authorize({
    interactive:false,
    success: onAuthorize
});

$("#connectLink")
.click(function(){
    Trello.authorize({
        type: "popup",
        success: onAuthorize
    })
});

$("#disconnect").click(logout);

The error I get is [object Object] 我得到的错误是[object Object]

I have also tried with this URL: 'cards/5ab7c3c631a2019c50b701c8/name?value=nombrecito' 我也尝试过以下URL: 'cards/5ab7c3c631a2019c50b701c8/name?value=nombrecito'

It looks like your Trello.put URL is a little off. 看起来您的Trello.put URL有点小了。

Fix the Trello.put with... 用...修复Trello.put

Trello.put("/boards/mecards/5ab7c3c631a2019c50b701c8/name?value=nombrecito", function () {}, function(err) {alert(err)});

Have you tried the live example on the documentation page? 您是否在文档页面上尝试过实时示例? It's not that complicated and something like this. 并不是那么复杂,像这样。

const API_KEY = 'your key';
const TOKEN = 'your token';

let id = 'your trello card id';
let newName = 'a new name what you want';

var data = null;
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});
xhr.open("PUT", "https://api.trello.com/1/cards/"+id+"?name="+newName+"&key="+API_KEY+"&token="+TOKEN);
xhr.send(data);

I've tested with my own cards and it works very well. 我已经用自己的卡进行了测试,效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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