【发布时间】:2015-10-20 09:16:00
【问题描述】:
【问题讨论】:
-
如in this thread 所述,似乎无法过滤某些错误,但您可以将它们全部禁用。
标签: javascript html ace-editor
【问题讨论】:
标签: javascript html ace-editor
试试这个
var session = editor.getSession();
session.on("changeAnnotation", function() {
var annotations = session.getAnnotations()||[], i = len = annotations.length;
while (i--) {
if(/doctype first\. Expected/.test(annotations[i].text)) {
annotations.splice(i, 1);
}
}
if(len>annotations.length) {
session.setAnnotations(annotations);
}
});
【讨论】:
Unexpected End of File. Expected DOCTYPE. - 这并不是什么大问题,但如果你更新它会很棒你的 sn-p 来反映这一点。 :)
带有“意外的文件结尾。预期的 DOCTYPE。”已过滤警告。
var session = editor.getSession();
session.on("changeAnnotation", function () {
var annotations = session.getAnnotations() || [], i = len = annotations.length;
while (i--) {
if (/doctype first\. Expected/.test(annotations[i].text)) {
annotations.splice(i, 1);
}
else if (/Unexpected End of file\. Expected/.test(annotations[i].text)) {
annotations.splice(i, 1);
}
}
if (len > annotations.length) {
session.setAnnotations(annotations);
}
});
【讨论】:
如果您直接对annotations 进行操作并直接调用编辑器onChangeAnnotation 方法来更新页面上的注释,则可以防止触发另一个changeAnnotation 事件并像克里斯的回答那样调用此事件处理程序两次。
var editor = Application.ace.edit(element),
session = editor.getSession();
session.on('changeAnnotation', function () {
session.$annotations = session.$annotations.filter(function(annotation){
return !(/doctype first\. Expected/.test(annotation.text) || /Unexpected End of file\. Expected/.test(annotation.text))
});
editor.$onChangeAnnotation();
});
【讨论】: