2015-12-30 62 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 –