gpt4 book ai didi

javascript - QuillJS 不会从 api 设置内容

转载 作者:行者123 更新时间:2023-11-30 11:43:18 25 4
gpt4 key购买 nike

我试图通过我的 api 调用(使用 ajax 请求)设置我的编辑器的内容,但是,它不会更新编辑器。我不确定为什么,因为当我这样做的时候

alert(data.content) -- it returns {"ops":[{"insert":"Test 123\n"}]}

quill.setContents({"ops":[{"insert":"Test 123\n"}]}, 'api');

按预期工作,但是,当我这样做时没有任何反应

quill.setContents(data.content, 'api')

有什么想法吗?谢谢!

最佳答案

setContents from APi正在工作。

var quill = new Quill('#editor-container', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
});

var ops = [
{ insert: 'Hello ' },
{ insert: 'World!', attributes: { bold: true } },
{ insert: '\n' }
];
quill.setContents(ops, 'api');

您可能传递的是字符串而不是对象。

尝试调用 JSON.parse(data.content) 将字符串转换为对象。

关于javascript - QuillJS 不会从 api 设置内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41886847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com