简体   繁体   中英

How do I resolve an AutoComplete error when using CodeMirror?

I want to use the AutoComplete of CodeMirror, but I'm getting the error:

Uncaught TypeError: Cannot read property 'javascript' of undefined

CodeMirror.commands.autocomplete = function(cm) {
    CodeMirror.showHint(cm, CodeMirror.hint.javascript); // Error Here
}

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    extraKeys: {"Ctrl-Space": "autocomplete"}
});

In order to use autocomplete capabilities, you must insure to include the appropriate scripts, ie show-hint.js , show-hint.css and javascript-hint.js (which seems like the one causing the fuss here).

Take a look at the autocomplete demo 's source code for a reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM