具有高级自动完成功能的 Angular TextEditor

Amr*_*man 3 jquery rich-text-editor angularjs angular-ui

我正在尝试为 Angular 找到一个好的富文本编辑器指令,它支持树状自动完成,这意味着:

例如,我可以传递一个用于自动完成的“建议”数组,每个“建议”都包含一个“文本”和一个用于嵌套“建议”的数组,等等。

而且,我可以使用“.”访问嵌套选项。例如。

所以,我通过它:

[{
  'text': 'parent1',
  'suggestions': [{
    'text': 'child1',
  }, {
    'text': 'child2'
  }]
}, {
  'text', 'parent2',
  'suggestions': [{
    'text': 'child3',
  }, {
    'text': 'child4'
  }]
}]
Run Code Online (Sandbox Code Playgroud)

用户可以写“p”来查看“parent1”和“parent2”作为建议。当他选择任何一个并按“.”时 他将其子项视为建议。

JQuery 选项也适合我。

Mos*_*Feu 5

您可以使用ace编辑器并添加自动完成功能:

var langTools = ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");
editor.setOptions({enableBasicAutocompletion: true});
// uses http://rhymebrain.com/api.html
var rhymeCompleter = {
  getCompletions: function(editor, session, pos, prefix, callback) {
    if (prefix.length === 0) { callback(null, []); return }
    $.getJSON(
      "http://rhymebrain.com/talk?function=getRhymes&word=" + prefix,
      function(wordList) {
        // wordList like [{"word":"flow","freq":24,"score":300,"flags":"bc","syllables":"1"}]
        callback(null, wordList.map(function(ea) {
          return {name: ea.word, value: ea.word, score: ea.score, meta: "rhyme"}
        }));
      })
  }
}
langTools.addCompleter(rhymeCompleter);
Run Code Online (Sandbox Code Playgroud)
<div id="editor" style="height: 500px; width: 800px">Type in a word like "will" below and press ctrl+space or alt+space to get "rhyme completion"</div>
<div id="commandline" style="position: absolute; bottom: 10px; height: 20px; width: 800px;"></div>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="https://rawgithub.com/ajaxorg/ace-builds/master/src/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="https://rawgithub.com/ajaxorg/ace-builds/master/src/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
Run Code Online (Sandbox Code Playgroud)

来源:https ://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor