简体   繁体   English

单引号字符串中的双引号 - NodeJs

[英]Double quotes within single quote string - NodeJs

I'm having quite a problem to which other answers pose no solution. 我有一个很大的问题,其他答案没有解决方案。 I'm trying to print out double quotes in a string literal. 我正在尝试在字符串文字中打印出双引号。 I, however, keep getting errors. 但是,我不断收到错误。

This is the specific function: 这是具体的功能:

app.put('/assignments/:name/assignee/:assignee', function (request, response) {
  logic.examine(request, function (mail, jobtitle) {
    if (mail !== request.params.assignee && jobtitle.indexOf('Personeel') === -1) {
      response.sendStatus(401);
    } else {
      logs_logic.addLog(mail + ' heeft gebruiker met naam "' + request.params.assignee + '" toegekend aan opdracht met als naam "' + request.params.name + '".');      
      response.status(200).json(logic.changeAssignee(request.params.name, request.params.assignee));
    }
  });
});

The error message reads 'Invalid or unexpected token' pointed to the part after the third 'plus' (or concat) sign. 错误消息显示在第三个“加号”(或连续)符号后指向该部分的“无效或意外令牌”。 So it starts at "toegekend" 所以它从“toegekend”开始

Any ideas? 有任何想法吗?

Thanks in advance! 提前致谢!

use es6 template literas aka backticks which will create more clarity in statements. 使用es6模板literas aka反引号,这将在语句中创建更多的清晰度。

`this is string ${some_variable} more text ${some_variable_2}`

logs_logic.addLog(`${mail} heeft gebruiker met naam " ${request.params.assignee} " toegekend aan opdracht met als naam " ${request.params.name} ".`);

Use backticks (`) to form the string instead of single quotes. 使用反引号(`)来形成字符串而不是单引号。

and use 并使用

${variable_name}

to use that variable in string. 在字符串中使用该变量。

Here is the example: 这是一个例子:

logs_logic.addLog(`${mail} heeft gebruiker met naam "${request.params.assignee}" toegekend aan opdracht met als naam "${request.params.name}".`);

Hope this helps. 希望这可以帮助。

Give the " 给出" literal a try and see if it works for you. 字面试试,看看它是否适合你。 Something like this: 'This is "quoted"' 这样的事情: 'This is "quoted"'

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

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