有没有一种方法可以通过id获取ace编辑器?

问题描述:

有没有一种方法可以通过id获得对ace编辑器的引用?有没有一种方法可以通过id获取ace编辑器?

Ace不保留对编辑器的引用,所以如果我需要获得对编辑器的引用,我该怎么做?

它看起来像我可以使用下面的代码:

ace.getEditorById = function(el) { 
    if (typeof el == "string") { 
     var _id = el; 
     el = document.getElementById(_id); 

     if (!el) { 
      return null; 
     } 

     if (el && el.env && el.env.editor instanceof Editor) { 
      return el.env.editor; 
     } 
    } 

    return null; 
} 

我想建议把它添加到核心。也许我们可以有一个ace.editors字典来跟踪它们。见问题1138

+0

ace.edit(“id”)已经这样做https://github.com/ajaxorg/ace/blob/v1.2.6/lib/ace/ace.js#L84-L85 –