[英]Ace editor: First instance becomes unresponsive after a second one is created
I'm using the ace editor for a small project I'm making.我正在将 ace 编辑器用于我正在制作的一个小项目。
I want multiple instances of the ace editor on my page我希望我的页面上有多个 ace 编辑器实例
I start with a global variable that will contain all other instances我从一个包含所有其他实例的全局变量开始
let editors = {};
let i = 0;
Then I create an instance like so:然后我像这样创建一个实例:
i++
editors[i] = ace.edit(`editor-${i}`);
editors[i].setTheme("ace/theme/cobalt");
editors[i].session.setMode("ace/mode/javascript");
This code works it creates the first instance without any issues.这段代码可以正常工作,它创建了第一个实例,没有任何问题。
Then comes the second instance and that works.然后是第二个实例,它起作用了。 But the first instance becomes unresponsive.
但是第一个实例变得没有响应。 I can't edit anything, Cant modify the theme using dev tools anymore.
我无法编辑任何内容,无法再使用开发工具修改主题。 And nothing works.
没有任何作用。 How to fix this exactly?
如何解决这个问题? I have been trying options with sessions and all, but nothing seems to work.
我一直在尝试使用会话和所有选项,但似乎没有任何效果。
Thank you very much非常感谢你
With kind regards, HyperDev亲切的问候, HyperDev
After alot, and i do mean alot of thinking and trying things i found the issue.在很多之后,我确实意味着很多思考和尝试我发现问题的事情。
What i was doing is appending an ace instance to a div using我正在做的是将一个 ace 实例附加到一个 div 使用
div.innerHTML += `<div id="editor-${i}"></div>`;
It turns out the instance stops when its set like that Instead i had to create an element in a variable.事实证明,当它像那样设置时,实例就会停止,而是我不得不在变量中创建一个元素。 And after that append it to the body using .appendChild now it works.
之后使用 .appendChild 将其附加到正文中,现在它可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.