2012-09-10 2 views
4

변경 이벤트의 테마를 Ace 편집기에서 어떻게 변경할 수 있습니까? 프로그래밍 방식으로 DOM 준비 이벤트에서 테마를 설정할 수 있습니다. 내가 (두 이벤트에 대해) 호출하는 코드는 아래와 같이 표시되며 ("ace/theme/clouds"/ "ace/theme/clouds_midnight")와 같은 값을 전달합니다.에이스 편집기 : 동적으로 테마를 변경하는 방법

setThemeValue = function(themeVal){ 
var editor = ace.edit("editor"); 
editor.setTheme(themeVal); 
editor.getSession().setMode("ace/mode/javascript"); 
}; 

답변

11

"그림 참고 "당신은 즉석에서 사용하는 테마를 변경, 당신은 ("편집기")를 ace.edit을 다시 할 필요가 없습니다.

그래서 나는 코드를 같이하는 대신 제안 :

// Initialize your Ace Editor 
var editor = (function() { 
    var aceEditor = ace.edit("editor"); 
    // default theme 
    aceEditor.setTheme("ace/theme/clouds"); 
    aceEditor.getSession().setMode("ace/mode/javascript"); 
    return aceEditor; 
})(); 

// Change theme on the fly 
editor.setTheme("ace/theme/clouds_midnight"); 
관련 문제