The below is working example for ace editor which shows autocomplete options using json file.
var langTools = ace.require("ace/ext/language_tools");
var editor = ace.edit("content");
editor.setOptions({enableBasicAutocompletion: true, enableLiveAutocompletion: true, tabSize: 2});
editor.getSession().setMode("ace/mode/yaml");
jsonURL = "func.json"; //JSON file
var rhymeCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
if (prefix.length === 0) { callback(null, []); return }
$.getJSON(
jsonURL,
function(wordList) {
callback(null, wordList.map(function(ea) {
return {name: ea.word, value: ea.word, meta: "artemis"}
}));
})
}
}
langTools.addCompleter(rhymeCompleter);
Json file
[ {"word":"iter"},
{"word":"arr"},
{"word":"s_time"},
{"word":"
arr.name"},
{"word":"
arr.id"}
]
I am trying to work on the feature of autocomplete by period.. for eg if user type "arr." we should give options id and name as autocomplete.
Please help in resolving the issue.