node.js - 如何在 node-js 中添加换行符?
问题描述
我正在尝试在 lambda 函数内的节点 js 中的两个字符串之间添加换行符。
我曾尝试使用 '\n' 、 '\r\n' 并尝试导入 os 然后使用 os.EOL 语句,但这些都不起作用。
------------------------Using '\n'-------------------------------
var msg = `The order(s) for the customer ${CustomerNumber} and its status are ${data}`
msg+='\n'
msg+= ' To know the order details of another customer enter the customer
-------------------------- Using '\r\n' -------------------------------
var msg = `The order(s) for the customer ${CustomerNumber} and its status are ${data}`
msg+='\n'
msg+= ' To know the order details of another customer enter the customer number'
-------------------------- Using 'os.EOL' -------------------------------
var os = require("os");
var msg = `The order(s) for the customer ${CustomerNumber} and its status are ${data}`+os.EOL+' To know the order details of another customer enter the customer number'
-------------- Sending msg string to the AWS lex bot----------------------
callback(elicitSlot(sessionAttributes, deliveryStatus, slots, "CustomerNumber", {
'contentType': 'PlainText',
'content': msg
} ));
function elicitSlot(sessionAttributes, intentName, slots, slotToElicit, message) {
return {
sessionAttributes,
dialogAction: {
type: 'ElicitSlot',
intentName,
slots,
slotToElicit,
message,
},
};
}
所有这些都有节点效应,我得到的输出没有换行符,并且是一个连续的字符串
我期望的输出是:“客户 abcd 的订单及其状态为 1234、5678、9876”要了解另一个客户的订单详细信息,请输入客户编号
输出我得到的是:“客户 abcd 的订单及其状态为 1234、5678、9876”要了解另一个客户的订单详细信息,请输入客户编号
我认为这是因为我将内容类型指定为“纯文本”,任何人都可以建议我一个解决方案吗?
解决方案
看起来这有点旧,但我在教程中找到了答案。要在消息中使用 html,您需要对消息使用反引号。例如:
event.response.emailMessage = `<h1>Welcome to the App!</h1> <p>Your user name is ` + event.request.usernameParameter + `</p> <p>Your temporary password: ` + event.request.codeParameter + `</p> <p>If you need assistance, please contact the help desk at (555) 555-5555 or email <a href="mailto:help@example.org">help@example.org.</a></p>`;
希望这会帮助其他人。
推荐阅读
- algorithm - BFS 和 DFS 算法有什么区别?
- javascript - hapi.js 没有从 mysql 返回值
- discord.js - 我正在尝试将状态和播放状态添加到我的用户信息命令
- python - Spacy 编辑/清理 PDF 文件中不那么重要的文本
- python - 如何在odoo中将自定义值从sales.order.line发送到stock.move
- c++ - 如何使用 Open MPI 让我的程序更快?我的 Open MPI 程序目前比原来的慢,我不明白什么?
- javascript - SAFARI 正在下载一个没有内容类型的 .download 文件(EXPRESS、NODE.JS)
- python - 处理唯一一起错误的最佳方法 - Django 2.2?
- python - 定期使用python从文件将Json数据发送到服务器
- unit-testing - 如何在测试用例中修复“复合文字中缺少类型”