我有一个实例化 ace 编辑器对象的 div
。
我正在尝试从 HTML draggable
中拖放
一些文本。
我已经将 ui-ace div droppable
设置为可以从 drop 的事件目标中获取编辑器的当前实例。
我怎样才能做到这一点???
HTML
<div id="id1" ui-ace droppable=true ondrop="handleDrop(event,this)"></div>
JS函数
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
}
我知道你问这个问题已经有一段时间了,但我找不到关于这个主题的任何东西,所以我想我应该分享这个。
关于javascript - 如何从其 Div id 获取 Ace Editor 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25452304/