【发布时间】:2014-04-24 19:35:46
【问题描述】:
我正在尝试使用下拉菜单来选择语言来实现 Ace 代码编辑器。我的下拉菜单有一个模式 id。我已经让编辑器正常工作,但我无法按照我的意愿使用下拉菜单更改语言。我当前的代码是
var editor = ace.edit("code");
var textarea = $('textarea[name="code"]').hide();
editor.setTheme("ace/theme/textmate");
editor.getSession().setMode("ace/mode/sql");
editor.getSession().setValue(textarea.val());
editor.getSession().on('change', function(){
textarea.val(editor.getSession().getValue());
});
$('#mode').on('change', function(){
var newMode = $("mode").val();
editor.session().setMode({
path: "ace/mode/" + newMode,
v: Date.now()});
});
如上所述,这成功启动了编辑器,但是我无法从 SQL 更改语言,这是初始语言。我遇到了这个问题Dynamically update syntax highlighting mode rules for the Ace Editor 这就是我加入的原因
v: Date.now()
但仍然没有运气。
【问题讨论】:
标签: javascript jquery syntax-highlighting ace-editor