Javascript 加载页面后获取Ace编辑器对象

Javascript 加载页面后获取Ace编辑器对象,javascript,ace-editor,Javascript,Ace Editor,我在下面的代码中成功地初始化了Ace编辑器元素 <script> var editor = ace.edit('Editor_@index'); editor.setTheme("ace/theme/tomorrow"); editor.getSession().setMode("ace/mode/csharp");

我在下面的代码中成功地初始化了Ace编辑器元素

                <script>
                    var editor = ace.edit('Editor_@index');

                    editor.setTheme("ace/theme/tomorrow");
                    editor.getSession().setMode("ace/mode/csharp");
                    editor.renderer.setShowGutter(false);
                    editor.setReadOnly(true);
                    editor.resize();
                    editor.setOptions({
                        maxLines: editor.session.getLength()
                    });
                </script>

var editor=ace.edit('editor@index');
编辑:setTheme(“ace/主题/明天”);
editor.getSession().setMode(“ace/mode/csharp”);
editor.renderer.setShowGotter(false);
editor.setReadOnly(true);
editor.resize();
editor.setOptions({
maxLines:editor.session.getLength()
});

但是在页面加载之后,我如何获取这些项目呢?页面上有许多编辑器,@index是可变的。

为什么不在页面加载后调用这些代码呢?然后,您可以在需要的地方调用
editor
。我将此代码用于@foreach循环,在该循环中,动态地从数据创建html代码,因此变量编辑器在每次迭代中都会被覆盖。您可以创建不同的变量,或创建编辑器数组,或添加一个js循环,该循环将遍历所有的“editor_@index”并创建编辑器。