getAllDecorations 不是函数

Ron*_*vdb 0 monaco-editor

我设法创建了行和内嵌装饰并将它们应用到编辑器,这是我用来创建装饰的代码:

editor.deltaDecorations([], myDecorations);
Run Code Online (Sandbox Code Playgroud)

现在我正在寻找一种去除装饰的方法。

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

var decs = editor.getAllDecorations();
Run Code Online (Sandbox Code Playgroud)

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

Uncaught TypeError: editor.getAllDecorations is not a function(…)
Run Code Online (Sandbox Code Playgroud)

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

pao*_*olo 5

getAllDecorations 函数是为模型对象定义的,而不是为editor定义的,如您在文档中所见

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

所以,你应该使用

editor.getModel().getAllDecorations();
Run Code Online (Sandbox Code Playgroud)