【问题标题】:Angular TextEditor with advanced autocomplete具有高级自动完成功能的 Angular TextEditor
【发布时间】:2016-05-13 21:06:51
【问题描述】:

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

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

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

所以,我通过了:

[{
  'text': 'parent1',
  'suggestions': [{
    'text': 'child1',
  }, {
    'text': 'child2'
  }]
}, {
  'text', 'parent2',
  'suggestions': [{
    'text': 'child3',
  }, {
    'text': 'child4'
  }]
}]

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

JQuery 选项也适用于我。

【问题讨论】:

    标签: jquery angularjs angular-ui rich-text-editor


    【解决方案1】:

    您可以使用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);
    <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>

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-24
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      • 2013-09-26
      • 2017-01-23
      • 1970-01-01
      相关资源
      最近更新 更多