最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get Ace Editor object from its Div id - Stack Overflow

programmeradmin1浏览0评论

I have a div which instantiates an ace editor object.

I am trying to drag and drop some text into it from an HTML draggable.

I have made the ui-ace div droppable and want to get the current instance of the editor from the event target of drop.

How can I accomplish this???

HTML

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

JS function

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. ;api=ace
}

Please help.

I have a div which instantiates an ace editor object.

I am trying to drag and drop some text into it from an HTML draggable.

I have made the ui-ace div droppable and want to get the current instance of the editor from the event target of drop.

How can I accomplish this???

HTML

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

JS function

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
}

Please help.

Share Improve this question edited Aug 22, 2014 at 17:28 Darshan Patel 2,8992 gold badges26 silver badges39 bronze badges asked Aug 22, 2014 at 17:12 user3779089user3779089 4192 gold badges6 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 25

I don't know why this is not mentioned in the API documentation, but if you call ace.edit on an already instantiated editor, you will get that instance. It will NOT reset that editor. I have tested it.

In your case, it could be accomplished by the following code:

function handleDrop(e,obj)
{
   var editor = ace.edit(obj.id);

   // Do something with editor
}

I know it has been a while since you have asked this question, but I couldn't find anything on this topic so I thought I should share this.

发布评论

评论列表(0)

  1. 暂无评论