2014-09-23 29 views
0

我有一些問題應用TinyMCE到textarea元素。 我有一張載有乘客名單的頁面。當你點擊一個乘客時,AJAX被調用,它顯示乘客的信息,一個字段碰巧是一個textarea元素。我的問題是,你點擊的第一個乘客(任何乘客)加載TinyMCE,但從這裏開始,這只是一個普通的textarea,沒有應用TinyMCE。我不知道發生了什麼事。這裏是我有以下代碼:TinyMCE沒有被添加到AJAX調用元素

j$ = jQuery.noConflict(); 
j$(document).ready(function(e) { 
    tinyMCE.init({ 
     mode : "textareas", 
     theme : "advanced", 
     theme_advanced_buttons1 : "bold, italic, underline, | ,bullist, numlist, | ,outdent, indent, | ,link, unlink, |, code", 
     relative_urls : false, 
     remove_script_host : false, 
    }); 

j$('.names strong').click(function(e) { 
    //Find passenger ID 
    var customer_ID = j$(this).closest('.passenger_Container').find("input[name='customer_ID']").val(); 
    //Find placement of returned data 
    var insert_Data = j$(this).closest('.passenger_Container').find('.package'); 

    j$.ajax({   
     type: "POST", 
     url: "/include/passenger_Detail.php", 
     data: { customer_ID_Data : customer_ID }, 
     success: function(data) { 
      //get returned data and add into appropriate place 
      insert_Data.html(data); 

      var oldEditor = tinyMCE.get('notes'); 
      if (oldEditor != undefined) { 
       tinymce.remove(oldEditor); 
      } 
      tinyMCE.execCommand('mceAddControl', false, 'notes'); 
      //re-initialise WYSIWYG editor. Notes is the ID to re-initialize 
      /*tinymce.execCommand('mceRemoveControl',true,'notes'); 
      tinymce.execCommand('mceAddControl',true,'notes');*/ 
     } 
    }); 
    }); 
}); 

<!-- content is displayed using PHP while loop --> 
<div class="passenger_Container bottom-buffer"> 
    <div class="names row"> 
     <div class="col-xs-1 text-center"> 
     <!-- Display checkbox --> 
     </div> 
     <div class="col-xs-4 col-sm-3"> 
      <strong><?php echo $row['f_Name'].' '.$row['l_Name']; ?></strong> </div> 
     <div class="col-xs-3 hidden-xs"> 
     <!-- display child names --> 
     </div> 
     <div class="col-xs-3"> 
     <!-- Display order status --> 
     </div> 
     <div class="col-xs-1 col-sm-2"> 
     <!-- Display form --> 
     </div> 
    </div> 

    <div class="package custom-well well-sm top-buffer"> 
     <!-- passenger detail goes here. You will find the code in includes/passenger_Detail.php --> 
    </div> 
</div> 
<!-- end PHP while loop --> 

我已經離開了我試圖讓TinyMCE工作的例子。我有一個偷偷摸摸的懷疑,不好的編碼習慣是罪魁禍首。每個textareas都有一個我認爲是原因的#notes ID。但看文檔我不認爲tinyMCE可以讓你使用類來定位textareas。除非我必須遍歷所有textareas。我只是在這裏吐口水。

請告知我是否需要更多信息。再次感謝。

回答

0

我最終解決了這個問題,但是爲每個textarea元素使用了唯一的ID。因此,而不是每個具有ID「註釋」的textarea,它現在是「notes_unique customer_ID」。

以下是我的回答:

j$.ajax({   
     type: "POST", 
     url: "/include/passenger_Detail.php", 
     data: { customer_ID_Data : customer_ID }, 
     success: function(data) { 
     //console.log("Returned data: "+data); 
     //get returned data and add into appropriate place 
     insert_Data.html(data); 
     notes = insert_Data.find('textarea').attr('id'); 
     var oldEditor = tinyMCE.get('notes_'+customer_ID); 
     if (oldEditor != undefined) { 
      tinymce.remove(oldEditor); 
     } 
     tinyMCE.execCommand('mceAddControl', false, 'notes_'+customer_ID); 
    } 
});