猿问

Zapier Javascript:意外令牌]-在IDE,Repl.it和Node v6.3.1

解决方案:


const pattern = /\](,)\s{2,}?/gm

let res = inputData.rows.replace(pattern, (match, group1, offset, string) => "]")

            .split(/\s{2,}/gm)

            .map(x => JSON.parse(x));


res = res[0];   //reassign to scrape an array layer

let resultString = '';


for (let i = 0; i < res[0].length; i += 1) {

  let cv = res[0][i];

  if (cv.length === 0) resultString += `    ${res[1][i]}: ${inputData.rows[2][i]}\n`

  else resultString += `${cv}\n    ${res[1][i]}: ${res[2][i]}\n`;

}


output = {KPI: resultString};

问题

在Zapier Zap中,我正在从Google表格中提取数据,并使用JS进行美化,以便稍后发送电子邮件。我碰到了以下错误消息:


SyntaxError: Unexpected token ]


  stringOfArraysToArrayOfArrays (eval at <anonymous> (/var/task/index.js:52:23), <anonymous>:22:52)

  theFunction (eval at <anonymous> (/var/task/index.js:52:23), <anonymous>:29:18)

  eval (eval at <anonymous> (/var/task/index.js:52:23), <anonymous>:51:20)

  Domain.<anonymous> (/var/task/index.js:53:5)

  Domain.run (domain.js:242:14)

  module.exports.handler (/var/task/index.js:51:5)

我尝试过的

我已成功在不同环境中(从本地IDE,Repl.It IDE和设置为Node v6.3.1的在线IDE)将最新版本的Node的代码运行回Node v6.3.1。他们都清楚了。我还尝试清除所有ES6 +语法的代码(没有示例数据)


数据示例

let inputData = {

  rows: `["Prioritized Tasks", "", "", "", "Operational Tasks", "", "", "", "Eight Dimensions", "", "", "", "", "", "", "", "Burn-Out", "", "", "", "", "", "", "", "", "", "Violations"], 

}


开满天机
浏览 95回答 1
1回答

犯罪嫌疑人X

这种方法可能有点实用。您需要首先将],每行中的替换为一个空字符串,我已使用此Regex对其进行了拆分。之后,我将字符串分割成两个以上字符的空格。然后,最后我习惯.map了在拆分后的项目上进行投影,以将其解析回并组成一个数组数组。const inputData = {&nbsp; rows: `["Prioritized Tasks", "", "", "", "Operational Tasks", "", "", "", "Eight Dimensions", "", "", "", "", "", "", "", "Burn-Out", "", "", "", "", "", "", "", "", "", "Violations"],&nbsp;&nbsp; &nbsp; ["Completion Rate", "Avg Completed", "Avg Total Scheduled", "Avg Time Spent", "Completion Rate", "Avg Completed", "Avg Total Scheduled", "Avg Time Spent", "Emotional", "Environmental", "Financial", "Intellectual", "Occupational", "Physical", "Social", "Spiritual", "Feeling Stressed", "Feeling Depleted", "Having Trouble Concentrating", "Feeling Forgetful", "Wanting to avoid social situations", "Feeling pessimistic", "Feeling cynical", "Feeling apathetic or disinterested", "Not feeling engaged with my work", "My overall energy level", "Temperance", "Silence", "Order", "Resolution", "Frugality", "Industry", "Sincerity", "Justice", "Moderation", "Cleanliness", "Tranquility", "Chastity", "Humility"],&nbsp;&nbsp; &nbsp; ["70.33", "4", "6.67", "380", "3.67", "3.67", "66.67", "100", "8", "5.33", "5.67", "4.67", "4", "5", "4.67", "6.67", "1.33", "4", "5", "4.67", "3.33", "3.33", "1.33", "5", "6", "5.67", "0.3333333333", "0.3333333333", "0.3333333333", "0", "1", "0", "0", "0", "0", "0.3333333333", "0.3333333333", "0.3333333333", "0.3333333333"]`};const pattern = /\](,)\s{2,}?/gmconst res = inputData.rows.replace(pattern, (match, group1, offset, string) => "]")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .split(/\s{2,}/gm)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .map(x => JSON.parse(x));const output = { KPI: res };console.log(output);
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答