2016-12-26 4 views
0

페이지에 여러 개의 에이스 편집기 인스턴스가있는 것을 계획하고 있으며 코어 라이브러리가 해당 라이브러리를 추적하고 있는지 알고 싶습니다. 그래서 나중에 쉽게 참조 할 수 있습니다.에이스 코어 클래스가 페이지의 모든 에디터 인스턴스를 추적합니까?

그렇지 않다면 사전이나 객체의 편집기 인스턴스를 유지하는 것이 좋습니다. 에이스 클래스에 객체를 만들 수 있을까요? 참조 또는 ID로 객체를 만들어야합니까?

var editor1 = ace.edit("myEditorDivID"); 
var editor2 = ace.edit("myEditorDivID2"); 
var editors = ace.editors; 

console(editor1==editors["myEditorDivID"]); // true 
console.log(editors["myEditorDivID"]); // editor1 

var editorIds = ace.editorIds; 

console.log(editorIds[0]); // myEditorDivID 

이러한 인스턴스에 대한 참조를 제거하는 데 사용되는 에이스 파괴 방법이 있습니까?

이 질문 중 두 번째 부분을주의하지 마십시오. 난 그냥 파괴하는 방법을 발견

editor.destroy(); 
editor.container.remove(); 

업데이트 :

가 난 그냥 뭔가 다른 생각. ID 또는 참조를 추적 할 수 있으면 동일한 ID 충돌을 방지 할 수 있습니다. 또한 페이지에있는 편집자 수를 추적하거나 우연히 여러 명이 작성하는 경우에도 도움이됩니다.

나는 단지 ace source을 보았으며 편집자가 생성 될 때 편집자를 추적하지는 않습니다. 뭔가를 채찍질하려고하거나 다른 사람이 그걸 해결하도록해야합니까?


업데이트 2 : 내가 editors 속성을 추가하고 ID로를 설정하는 생각하고

. 제안과 함께 답을 추가했습니다.

+0

모든 에이스 편집기 인스턴스를 가져올 수있는 방법이 있습니까? –

답변

0

내 질문에 답하는 중입니다. 그렇지 않습니다. 하지만 다음과 같은 의사 코드를 제안합니다.

ace.addEditorById = function (id, editor) { 
    if (ace.editors[id]!=null) throw Error ("Editor already created"); 
    ace.editors[id] = editor; 
} 

ace.getEditorById = function (id) { 
    return ace.editors[id]; 
} 

ace.removeEditorById = function (id) { 
    var editor = ace.editors[id]; 
    if (editor) { 
     editor.destroy(); 
     editor.container.remove(); 
     delete ace.editors[id]; 
    } 
} 

ace.editors = {}; 

// then when I create an editor I use the following code: 
editor = ace.edit("editor1"); 
ace.addEditorById(editor); 
editor2 = ace.edit("editor2"); 
ace.addEditorById(editor2); 

아마도 편집 호출에 편집기를 추가 할 수 있습니다. 어떻게 생각해?