【发布时间】:2020-01-22 07:49:18
【问题描述】:
当我尝试使用 javascript strapi sdk 更新我的数据库时,我总是得到Syntax Error: Unterminated string。 this.chapter.content 是 ckeditor 生成的 html 字符串。如何转义此字符串以使用 graphql 更新我的数据库?
async updateChapter() {
const q = `
mutation {
updateChapter(input: {
where: {
id: "${this.$route.params.chapterId}"
},
data: {
content: "${this.chapter.content.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/(?:\r\n|\r|\n)/g, '\n')}"
title: "${this.chapter.title}"
}
}) {
chapter{
title
id
content
}
}
}
`;
const res = await strapi.request("post", "/graphql", {
data: {
query: q
}
});
this.chapter = res.data.chapter;
}
【问题讨论】: