getAllDecorations 不是函数

getAllDecorations is not a function

我已经成功地创建了行和行内装饰并将它们应用到编辑器,这是我用来创建装饰的代码:

editor.deltaDecorations([], myDecorations);

现在正在寻找去除装饰的方法

我尝试了 API 文档 https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.itextmodelwithdecorations.html#getalldecorations 中描述的 getAllDecorations,但是当我尝试像这样使用它时:

var decs = editor.getAllDecorations();

我在浏览器的控制台中收到以下错误:

Uncaught TypeError: editor.getAllDecorations is not a function(…)

任何关于我做错了什么的建议将不胜感激! TIA

getAllDecorations 函数是为 model 对象定义的,而不是 editor,正如您在文档

中看到的那样

https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.imodel.html#getalldecorations

所以,你应该使用

editor.getModel().getAllDecorations();