在ace编辑器中动态自动完成

时间:2016-07-15 08:49:40

标签: javascript node.js ace-editor

我想根据字符串更新自动填充建议。

  aceeditorObj.completers.push({
        getCompletions: function(editor, session, pos, prefix, callback) {
            obj = editor.getSession().getTokenAt(pos.row, pos.column-count);
            if(obj.value === "student"){
                var wordList = ["name", "age" , "surname"];
                callback(null, wordList.map(function(word) {
                    return {
                        caption: word,
                        value: word,
                        meta: "static"
                    };
                }));

            }

        }
    });

姓名,年龄和姓氏将添加到自动建议列表中。但旧的仍然存在。如何在自动完成列表中仅显示新的世界列表?

1 个答案:

答案 0 :(得分:1)

尝试在调用完成函数后将语言工具设置为空白:

    var langTools = ace.require("ace/ext/language_tools");

    aceeditorObj.completers.push({
        getCompletions: function(editor, session, pos, prefix, callback) {
            obj = editor.getSession().getTokenAt(pos.row, pos.column-count);
            if(obj.value === "student"){
                var wordList = ["name", "age" , "surname"];
                callback(null, wordList.map(function(word) {
                    return {
                        caption: word,
                        value: word,
                        meta: "static"
                    };
                }));
            }
        }
    });

    langTools.setCompleters([]); // This function should clear them