Ace代码编辑器自动完成无效

时间:2015-07-24 05:27:13

标签: javascript jquery html ace-editor

我有一个textarea,在浏览器中变成了一个ace代码编辑器。基本上它只是将textarea模仿为div然后获取提交值。

自动完成功能无效。这是我的剧本:

 context = dict(self._context or {})

 data = self.browse([], context)[0]

如果我删除$(function () { $('textarea[data-editor]').each(function () { var textarea = $(this); var mode = textarea.data('editor'); var editDiv = $('<div>', { position: 'absolute', height: textarea.height(), 'class': textarea.attr('class') }).insertBefore(textarea); textarea.css('display', 'none'); var editor = ace.edit(editDiv[0]); editor.getSession().setValue(textarea.val()); editor.getSession().setMode("ace/mode/" + mode); // enable autocompletion and snippets ace.require("ace/ext/language_tools"); editor.setOptions({ enableSnippets: true, enableBasicAutocompletion: true, enableEmmet: true }); // editor.setTheme("ace/theme/idle_fingers"); editor.getSession().setUseWorker(false); editor.session.setFoldStyle('manual'); editor.setShowPrintMargin(false); // copy back to textarea on form submit... textarea.closest('form').submit(function () { textarea.val(editor.getSession().getValue()); }) }); }); 内的所有内容并运行

$('textarea[data-editor]').each(function () {

它工作正常。我做错了什么?

1 个答案:

答案 0 :(得分:0)

可能您设置的错误模式没有任何完成。 版本低于工作

&#13;
&#13;
$(function() {
  $('textarea[data-editor]').each(function() {
    var textarea = $(this);
    var mode = textarea.data('editor');
    var editDiv = $('<div>', {
      position: 'absolute',
      height: textarea.height(),
      'class': textarea.attr('class')
    }).insertBefore(textarea);
    textarea.css('display', 'none');
    var editor = ace.edit(editDiv[0]);
    editor.session.setValue(textarea.val());
    editor.session.setMode("ace/mode/" + mode);
    
    // enable autocompletion and snippets
    ace.require("ace/ext/language_tools");
    editor.setOptions({
      enableSnippets: true,
      enableBasicAutocompletion: true,
      enableEmmet: true,
      useWorker: false,
      theme: "ace/theme/idle_fingers",
      showPrintMargin: false,
      showFoldWidgets: false
    });
    // copy back to textarea on form submit...
    textarea.closest('form').submit(function() {
      textarea.val(editor.getSession().getValue());
    })
  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajaxorg.github.io/ace-builds/src/ace.js"></script>
<script src="https://ajaxorg.github.io/ace-builds/src/ext-language_tools.js"></script>
<script src="https://ajaxorg.github.io/ace-builds/src/ext-emmet.js"></script>


<form>
  <textarea data-editor='javascript' rows="10">{
}</textarea>
  <input type="submit" value="Submit">
</form>
&#13;
&#13;
&#13;

相关问题