2013-05-14 55 views
2

我使用:引導和wysihtml5更新textarea的

  • wysihtml5
  • 引導-wysihtml5.js

我有一個名爲Booking_CancellationComments_CancellationPolicy textarea的和我使其使用此代碼wysihtml5的textarea :

$('#Booking_CancellationComments_CancellationPolicy').wysihtml5(options); 

我想在稍後使用時更新它:

$('#Booking_CancellationComments_CancellationPolicy').val(data.Booking.CancellationComments.CancellationPolicy); 

但textarea沒有更新。我已經看了很多堆棧溢出的答案,並沒有展示如何使用我已經使用的初始化方法來更新textarea。

任何幫助表示讚賞。

回答

7

試試這個:

$('#Booking_CancellationComments_CancellationPolicy').data("wysihtml5").editor.setValue(data.Booking.CancellationComments.CancellationPolicy);

+0

如果$(「#Description」)。data('wysihtml5')。editor = 未定義,會出現什麼問題。謝謝。 – 2015-01-28 12:03:44

+0

你的答案適合我。非常感謝.. – Chintan7027 2015-09-24 08:01:25

1

//爲編輯=不確定。構造函數不初始化編輯

var wysihtml5 = $("#Booking_CancellationComments_CancellationPolicy").wysihtml5() ; 
wysihtml5 = wysihtml5.data("wysihtml5"); 
wysihtml5.createEditor({}); "create the editor 

....

wysihtml5.editor.setValue("some html"); 
0

我與編輯== '未定義' 同樣的問題,這個解決它:

$('.wysihtml5-sandbox').contents().find('body').html('<b>New text</a>'); 

我知道,這不是最好的解決方案,但只有這對我有用。如果你有更好的解決方案,請告訴我。