三重反斜杠“\\\”是什么意思?

时间:2021-03-18 09:56:53

标签: javascript reactjs amazon-web-services aws-lambda vtl

我正在开发由 VTL(Velocity 模板语言)库和 graphql 架构组成的 aws 项目。该数据库也是aws,尤其是dynamodb。现在它通过“\”向数据库发送(变异)数据。我想知道“\”是什么意思?

mutations.forEach((mutation) => {
  let details = `\\\"id\\\": \\\"$ctx.args.id\\\"`;

  if (mutation === "addLolly") {
    //details = `\\\"color1\\\":\\\"$ctx.args.lolly.color1\\\" , \\\"color2\\\":\\\"$ctx.args.lolly.color2\\\", \\\"color3\\\":\\\"$ctx.args.lolly.color3\\\", \\\"sender\\\":\\\"$ctx.args.lolly.sender\\\", \\\"reciever\\\":\\\"$ctx.args.lolly.reciever\\\", \\\"message\\\":\\\"$ctx.args.lolly.message\\\", \\\"link\\\":\\\"$ctx.args.lolly.link\\\"`;
    details = `\\\"color1\\\":\\\"$ctx.args.lolly.color1\\\" , \\\"color2\\\":\\\"$ctx.args.lolly.color2\\\" , \\\"color3\\\":\\\"$ctx.args.lolly.color3\\\" ,\\\"reciever\\\":\\\"$ctx.args.lolly.reciever\\\" ,\\\"sender\\\":\\\"$ctx.args.lolly.sender\\\" , \\\"message\\\":\\\"$ctx.args.lolly.message\\\" , \\\"link\\\":\\\"$ctx.args.lolly.link\\\"`;

  }

1 个答案:

答案 0 :(得分:1)

我们必须在字符串中的反斜杠后面添加一个额外的反斜杠来转义它们。

const str2 = '\\'; // is valid = 1 backslash
const str1 = '\'; // is invalid = error
const str3 = '\\\'; // is therefore invalid  = error
const str6 = '\\\\\\'; // is valid  = 3 backslashes