如何从它的Div id获得Ace编辑器对象

How to get Ace Editor object from its Div id

本文关键字:获得 Ace 编辑器 对象 id Div      更新时间:2023-09-26

我有一个实例化一个ace编辑器对象的div

我正在尝试从HTML draggabledrag and drop一些文本到它。

我已经制作了ui-ace div droppable,并希望从drop的事件目标中获得编辑器的当前实例。

我怎样才能做到这一点??

<div id="id1" ui-ace droppable=true ondrop="handleDrop(event,this)"></div>
<

JS函数/strong>

function handleDrop(e,obj){
   // need code to get current editor instance from obj without using ace.edit(obj.id)
   // because ace.edit(obj.id) will reset the content I believe. Please correct me if I am 
   //wrong. Ace api says it will insert editor in the DOM. http://ace.c9.io/#nav=api&api=ace
}

请帮。

我不知道为什么在API文档中没有提到这一点,但是如果您在已经实例化的编辑器上调用ace.edit,您将获得该实例。它不会重置编辑器。我已经测试过了。

在您的示例中,可以通过以下代码完成:

function handleDrop(e,obj)
{
   var editor = ace.edit(obj.id);
   // Do something with editor
}

我知道你问这个问题已经有一段时间了,但是我找不到任何关于这个话题的东西,所以我想我应该分享一下。