2011-02-14 2 views
2

젠드 프레임 워크로 개발중인 시스템과 함께 tinyMCE 편집기를 통합하려고합니다.tinymce getContent()가 아약스에서로드 할 때 빈 문자열을 반환합니다.

는 다음 TinyMCE를 편집기 코드의 부분보기 코드입니다

<script type="text/javascript" src="<?php echo $this->baseUrl()?>/js/tinymce/jquery.tinymce.js"></script> 
<script type="text/javascript" src="<?php echo $this->baseUrl()?>/js/jquery.validate.tinymce.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $('textarea.editor').tinymce({ 
      script_url : '<?php echo $this->baseUrl()?>/js/tinymce/tiny_mce.js', 

      // General options 
      theme : "advanced", 
      plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist", 

      // Theme options 
      theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect", 
      theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", 
      theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", 
      theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak", 
      theme_advanced_toolbar_location : "top", 
      theme_advanced_toolbar_align : "left", 
      theme_advanced_statusbar_location : "bottom", 
      theme_advanced_resizing : true 
     }); 
    }); 
</script> 

문제는 뷰가, 아약스에로드 될 때 호출 제출 버튼의 클릭 이벤트에 다음과 같은 것이있다 :

var content = tinyMCE.get('body').getContent(); 
    alert(content); 

반환 값은 빈 문자열입니다. 보기가 정상적으로로드되면 모든 것이 정상적으로 작동합니다. FF로만 제공됩니다. Chrome과 IE8은 Ajax에서도 잘 작동합니다.

누구도 이전에이 경험이 있습니까?

편집 : 기본적으로 내 앱은 MVC 구조를 사용하고 있습니다. 뷰는 MVC의 V 부분입니다. 브라우저에로드되는 기본 페이지는 "새로 추가"버튼이 포함 된 항목 목록 페이지입니다. 클릭하면 새로운보기가 아약스를 통해로드되고 페이지에 추가됩니다. 로드 된보기에는 주석과 HTML의 모든 자바 스크립트 코드가 모두 들어 있습니다. FF로 작동하지 않는 getContent() 호출을 제외하고는 모두 작동합니다.

+0

당신이 무엇을 보기와 아약스와 무슨 뜻입니까? 당신이 무엇을하고 무슨 일이 일어나는지 더 정확하게 알려주세요. – Thariama

+0

@Thariama, Edit added – Maverick

답변

3

내 자신과 "고치기"는 야수이다. 넓은 스트로크에서 Tiny 저장소는 인스턴스의 DOM 요소 (document, body, contentFrame, contentWindow)를 참조합니다. 나는 내부 DOM, Selection 및 다른 유틸리티에 의해 생성 된 클로저에서 그것들에 대한 참조를 만드는 것을 끝낸다는 것을 (그러나 100 % 확실하지는 않다) 생각한다. 이렇게하면 변경 사항을 볼 때 기존 DOM이 날아가고 새로운 ID (동일한 ID가있는 ID)로 대체되지만 내부 참조는 유지됩니다.

의 RTE 영역을 다시 그린다 코드 호출하기 전에 같은 전화를 내가 IEX, FF3.x, 웹킷 (크롬 & 사파리)를 지원하기 위해 구현하는 데 필요한 솔루션이었다

for(var i=0, n=tinymce.editors.length; i<n; i++) { 
    tinymce.editors[i].destroy(); 
    delete document.getElementById(tinymce.editors[i].id); 
} 
2

확실하지 않지만, 같은 id를 가진 여러 개의 tinymce 인스턴스로 인해 발생할 수 있습니다.

방화 광을 사용하는 경우이를 확인해보십시오.

for (var i = 0; i < tinymce.editors.length; i++) { 
    console.log(tinymce.editors[i].id); 
} 

이드가 2 배인 경우 문제의 근본 원인이 있습니다.

관련 문제