【问题标题】:Ace Code editor disappears onclickAce Code 编辑器在单击时消失
【发布时间】:2016-08-08 17:03:33
【问题描述】:

我在我的页面中嵌入了 ace-widget。我添加了一个使用 getvalue() 方法读取编辑器会话值的按钮。单击按钮后编辑器消失。可能是什么原因导致错误?请在下面的链接中找到屏幕截图。

<ace-widget id="editor1" initial-focus theme="ace/theme/monokai" mode="ace/mode/json" softtabs="true" wrap="true">
            This is a nice widget... and we are writing a long text here to show the effects of the `wrap` attribute.
          </ace-widget>       
          <paper-button raised class="custom indigo" onclick="myrun()">Run</paper-button>             
          <paper-textarea label="autoresizing textarea input"></paper-textarea>
          <script type="text/javascript">
            function myrun(){
              var editor = ace.edit("editor1");
              var myVar = editor.getSession().getValue();
              myVar= myVar.replace(/\d+/, '');
              myVar = myVar.substring(0,myVar.indexOf('XXXXXXX'));
              alert(myVar);
            }
          </script>

Screenshot

【问题讨论】:

    标签: javascript html web polymer-1.0 ace-editor


    【解决方案1】:

    您需要使用document.getElementById("editor1").editor 而不是ace.edit("editor1")

    <script src="https://rawgit.com/ajaxorg/ace-builds/master/src/ace.js"></script>
    <script src="https://rawgit.com/ajaxorg/ace-builds/master/src/ext-language_tools.js"></script>
    <link   rel="import" href="https://rawgit.com/Download/polymer-cdn/master/lib/polymer/polymer.html">
    <link   rel="import" href="https://rawgit.com/LostInBrittany/ace-widget/master/ace-widget.html">
    <link   rel="import" href="https://rawgit.com/Download/polymer-cdn/master/lib/paper-elements/paper-elements.html">
    
    
    <ace-widget id="editor1" initial-focus theme="ace/theme/monokai" mode="ace/mode/json" softtabs="true" wrap="true">
                This is a nice widget... and we are writing a long text here to show the effects of the `wrap` attribute.
    </ace-widget>       
    <paper-button raised class="custom indigo" onclick="myrun()">Run</paper-button>             
    <paper-textarea label="autoresizing textarea input"></paper-textarea>
    <script type="text/javascript">
        function myrun() {
            var editor = document.getElementById("editor1").editor
            var myVar = editor.session.getValue();
            myVar= myVar.replace(/\d+/, '');
            myVar = myVar.substring(0,myVar.indexOf('XXXXXXX'));
            alert(myVar);
        }
    </script>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      相关资源
      最近更新 更多