我试图从我的 api 调用(使用 ajax 请求)设置我的编辑器的内容,但是,它不会更新编辑器。我不知道为什么,因为当我这样做的时候
alert(data.content) -- it returns {"ops":[{"insert":"Test 123\n"}]}
Run Code Online (Sandbox Code Playgroud)
和
quill.setContents({"ops":[{"insert":"Test 123\n"}]}, 'api');
Run Code Online (Sandbox Code Playgroud)
按预期工作,但是,当我这样做时没有任何反应
quill.setContents(data.content, 'api')
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
小智 8
来自 APi 的 setContents正在工作。
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');
Run Code Online (Sandbox Code Playgroud)
您可能正在传递一个字符串而不是一个对象。
尝试调用 JSON.parse(data.content) 将字符串转换为对象。