Psy*_*lex 3 javascript arrays hash google-apps-script trello
本周我一直在尝试使用Trello和Google Apps脚本.我正在尝试创建一个哈希数组,然后我可以使用它来加载电子表格.Google应用脚本不喜欢创建哈希的典型JavaScript代码.我查了一下文档,但是他们没有像哈希那样的东西......他们对:
var object = [];
var object1 = {};
object.push(object1);
Run Code Online (Sandbox Code Playgroud)
这不会起作用,因为我基本上试图做类似的事情:
var hash={name: , label: };
var n= someNumber;
var l= someLabel
var hash.push(name: n, label: l);
Run Code Online (Sandbox Code Playgroud)
基本上这就是我现在的代码.但这是我的整个功能:
function getData(){
var list={};
//get the list of delivered cards from Trello
var listRequest = authorizeToTrello(); // get authorization
var result = UrlFetchApp.fetch("https://trello.com/1/lists/4fea3a2c3a7038911ebff2d8/cards",
listRequest);//fetch list
var listOfCards = Utilities.jsonParse(result.getContentText());//Google app utility format json
//outer loop to iterate through list of Cards
for(var i=0; i < listOfCards.length; i++){
var cardId = listOfCards[i].id; //get the id of a single card
var l = listOfCards[i]["label"]; //get the label for the our structure
//get a json object for a single card within the list of cards iteration
var cardRequest = authorizeToTrello();
var getCard = UrlFetchApp.fetch("https://trello.com/1/cards/" + cardId + "/actions", cardRequest);
var singleCard = Utilities.jsonParse(getCard.getContentText());
//inner loop to iterate the single cards JSON objects
for(var j=0; j < singleCard.length; j++) {
if(singleCard[j].data != undefined && singleCard[j].data.listAfter != undefined)
{
var str = singleCard[j]["data"]["listAfter"]['name'];
if(str === "Delivered Q3 2012"){
var n = singleCard[j]['memberCreator']['fullName'];
}
}
}
//push the data to list
list.push(n,l);
}
return name, label; //return list for output
}
Run Code Online (Sandbox Code Playgroud)
meg*_*024 10
阅读这个问题,我理解作者需要知道如何在GAS中创建一个关联数组.如果它是正确的,那么这里有几个链接(这里和这里),下面是一个示例代码.
function testMap() {
var map = {};
map["name1"] = "value1";
map["name2"] = "value2";
return map;
}
Run Code Online (Sandbox Code Playgroud)
如果作者需要真的
一系列哈希
然后有几种方法取决于需要哪种哈希算法.
以下是如何使用MD5哈希创建哈希数组的示例.
function testHash() {
var array = [];
array.push(Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, "value1"));
array.push(Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, "value2"));
return array;
}
Run Code Online (Sandbox Code Playgroud)
PS作者代码的返回行return name, label; //return list for output
不正确 - 仅label返回变量值.要将几个变量作为数组返回是必要的return [name, label];.或者可能是作者需要返回list变量而不是name和label.
| 归档时间: |
|
| 查看次数: |
23229 次 |
| 最近记录: |