当我收到一封电子邮件的内容时,它的格式是换行符,但当我将它发送到 API 时,结果是没有空格的文本。有什么办法可以保持间距?编辑:const postNewTask = (taskTitle, taskComment, workerId) => { const { projectId, tasklistId } = dataStore(); const { userEmail, apiKey } = credentialsStore(); const options = { method: 'POST', headers: { Authorization: 'Basic ' + Utilities.base64Encode(`${userEmail}:${apiKey}`), }, }; if (taskComment && workerId) { options.payload = JSON.stringify({ name: taskTitle, comment: { content: taskComment, }, worker: parseInt(workerId), }); }
1 回答
烙印99
TA贡献1829条经验 获得超13个赞
我解决了。我只需要使用taskComment.replace(/(?:\r\n|\r|\n)/g, '<br>'),API 就知道该怎么做。
最终工作代码:
const postNewTask = (taskTitle, taskComment, workerId) => {
const { projectId, tasklistId } = dataStore();
const { userEmail, apiKey } = credentialsStore();
const options = {
method: 'POST',
headers: {
Authorization:
'Basic ' + Utilities.base64Encode(`${userEmail}:${apiKey}`),
},
};
if (taskComment && workerId) {
options.payload = JSON.stringify({
name: taskTitle,
comment: {
content: taskComment.replace(/(?:\r\n|\r|\n)/g, '<br>'),
},
worker: parseInt(workerId),
});
添加回答
举报
0/150
提交
取消