2015-12-30 63 views
2

在'put'请求更新对象字段之后,我遇到ACE编辑器问题(使用django rest framework,它使用PUT/PATCH/DELETE/OPTIONS方法使用Ajax Form) 。放置请求后ACE编辑器呈现错误

我目前在表单中隐藏一个textarea,并用ace编辑器替换,更改textarea时更改了编辑器的内容。

然而,在说 - 会发生以下情况

before submit

成为

after submit

,我不知道怎么回事。可能是ace/css/ace_editor.css没有加载,但我不知道为什么会发生这种情况...

任何帮助将不胜感激!

 $(function() { 
 
       $('textarea[name=SQL]').each(function() {   
 
 
        console.log('new editor');

 
 
        $('form').find('textarea[name=SQL]').attr('id','textarea-code'); 
 
        $('#textarea-code').parent().append('<div id="ace-editor" class="ace-editor-class" style="height: auto;min-height:100px"></div>');

 
 
        var editor = ace.edit("ace-editor");
 
 
        editor.setTheme("ace/theme/crimson_editor");
 
 
        editor.getSession().setMode("ace/mode/sql");

 
 
        var textarea = $('#textarea-code').css('display', 'none');
 
 
        editor.getSession().setValue(textarea.val());

 
 
        editor.getSession().on('change', function(){ 
 
        textarea.val(editor.getSession().getValue());
 
 
        editor.resize(true);
 
 
        }); 
 
       }); 
 
      });

+0

你的意思是“在http放置请求后”和“放置”是什么意思?哪些资源正在“推出”?这个HTML在HTTP PUT请求中吗? –

+0

用更多的信息更新了问题:) – Liz

回答

1

临时解决方法: 看来编辑器缺少一些重要的CSS(.ace_editor)。解决办法是拷贝ace.js的行14388:

var editorCss = ".ace_editor {\ ... 

成一个本地的css文件(全部去掉\ first)。

+0

看起来像放后要求删除ace添加的样式标签给editorCss –