聊天紀錄至google sheet 的程式碼
function doPost(e) {
if (e) {
var estringa = JSON.parse(e.postData.contents);
var d = new Date();
// var e = estringa.message.from.id;
var SpreadSheet = SpreadsheetApp.openById("1FEN_9j410Lj-baZvnS5loZHloTMXBeJWUvSzuDTKzxU"); //試算表ID
var Sheet = SpreadSheet.getSheetByName("收到的訊息");
var LastRow = Sheet.getLastRow();
Sheet.getRange(LastRow + 1, 1).setValue(d);
// Sheet.getRange(LastRow + 1, 2).setValue(e);
Sheet.getRange(LastRow + 1, 3).setValue(estringa);
}
}
{
"message": {
"date": 1.61242727e9,
"chat": {
"first_name": "Charles",
"last_name": "W",
"id": "9.98115671E8",
"type": "private"
},
"from": {
"id": "9.98115671E8",
"is_bot": "false",
"language_code": "zh-hant",
"last_name": "W",
"first_name": "Charles"
},
"message_id": "25.0",
"text": "ccccc"
},
"update_id": 5.98994473e8
}
[checked]="cc[i].ans1Test === '1'"
lodash 裝下 result
{
"1": [
{
"b": 1
},
{
"b": 2
}
],
"2": [
{
"b": 1
},
{
"b": 2
},
{
"b": 3
}
],
"3": [
{
"b": 1
},
{
"b": 2
},
{
"b": 3
},
{
"b": 4
}
]
}
let arr = [
{a:1,b:1},
{a:1,b:2},
{a:2,b:1},
{a:2,b:2},
{a:2,b:3},
{a:3,b:1},
{a:3,b:2},
{a:3,b:3},
{a:3,b:4},
]
.mapValues(.groupBy(arr, 'a'),
clist => clist.map(arr => _.omit(arr, 'a')));
let group = arr.reduce((r, a) => {
r[a.a] = [...r[a.a] || [], a];
return r;
}, {});
console.log("group", group);
這個輸出完會是
[
[{},{}],
[{},{},{}],
[{},{},{},{}]
]
阿對了 如果想要更好看剛剛那個版本可以裝
lodash
_.groupBy(arr, 'a') 就結束了...
留言
張貼留言