Pregunta

I got the editor ace.js running on my site. Now when the user submits his code, a php file checks for correctness. If there are errors, I get an Array (errorArray) with the line numbers of the errors. E.g. there is 3, 17, 35. Now when I try to set arror annotations to the code editor, it only sets a annotation next to the last line in the array (in this example 35).

This is the code:

$("#tipp").click(function(){

                        // wenn tipp geklickt
                            var str = response;
                            var errorArray = str.split(" ");
                            $(".errors").append(' <div class="alert alert-warning alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Hier sind deine Fehler!</div>');  
                            for(var i=0; i<errorArray.length-1; i++){
                                console.log(errorArray[i]);
                                editor.getSession().setAnnotations([{
                                    row: errorArray[i]-1,
                                    text: "Hier stimmt was nicht",
                                    type: "error" // also warning and information
                                }]);
                            }    
                        });

Any suggestions how every line, which is in the array, gets an error annotation? Thx!

¿Fue útil?

Solución

Call setAnnotations once. e.g like this

editor.getSession().setAnnotations(errorArray.map(function(x) {
    return {
        row: x-1,
        text: "Hier stimmt was nicht",
        type: "error" // also warning and information
    }
}));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top