gpt4 book ai didi

javascript - Ace Editor 在单行上获取值

转载 作者:太空狗 更新时间:2023-10-29 13:45:34 26 4
gpt4 key购买 nike

我正在尝试在 Ace 编辑器上获取单行值。

根据 Ace Editor 文档:

  • gotoLine() 导航到单行
  • getLine() 获取单行
  • getLines() 获取多行

这是我尝试过的:

var html = ace.edit("html");

html.getSession().setMode("ace/mode/html");
html.setTheme("ace/theme/eclipse");
html.setPrintMarginColumn(false);
html.resize();

var line4 = html.gotoLine(4);
var getfour = html.getLine(4);
var getfoureight = html.getLines(4,8);

gotoLine() 有效。 getLine()getLines() 不起作用。

我做错了什么?

最佳答案

getLinegetLines 是 session 中的函数,所以你需要这样调用它们

var editor = ace.edit("html");
editor.setValue("line0 \n line1 \n line2 \n line3")
editor.session.getLine(2) // returns " line2 "
editor.session.getLines(1, 2) // returns [" line1 ", " line2 "]

关于javascript - Ace Editor 在单行上获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25835263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com