2015-04-16 30 views
0

我在Github上關注如何根據您放置的textarea ID或類獲取wysihtml5實例。這顯示的jsfiddle我遇到了錯誤:bootstrap-wysiwyg獲取實例未定義

http://jsfiddle.net/ez3ajvaf/2/

這是我的HTML:

<span class="footer-btn quote" rel=".text-editor" data-text="body-1"><span class="icon"><i class="fa fa-quote-left"></i></span> Quote</span> 

<textarea name="body" class="text-editor text-countdown" placeholder="Please allow up to 2,000 characters" maxlength="2000" data-rel="countdown" id="body" required></textarea> 

<div class="countdown-wrapper"> 
    <span id="countdown" class="countdown"></span> 
</div> 

這是我的javascript:

$('.text-editor').wysihtml5({ 
    toolbar: { 
     "font-styles": true, //Font styling, e.g. h1, h2, etc. Default true 
     "emphasis": true, //Italics, bold, etc. Default true 
     "lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true 
     "html": false, //Button which allows you to edit the generated HTML. Default false 
     "link": true, //Button to insert a link. Default true 
     "image": true, //Button to insert an image. Default true, 
     "color": false, //Button to change color of font 
     "blockquote": true, //Blockquote 
    } 
}); 

$('.quote').on('click', function() { 

    console.log('clicked'); 

    var textarea = $(this).attr('rel'); 

    console.log($(textarea).data("wysihtml5").editor); 

    $(textarea).data("wysihtml5").editor.html('hello'); 

}); 

錯誤我收到是

Uncaught TypeError: Cannot read property 'html' of undefined

在他們的github下https://github.com/bootstrap-wysiwyg/bootstrap3-wysiwyg如果你向下滾動到「你可以像這樣訪問wysihtml5編輯器對象」,它會根據他們發起的wysihtml5的textarea ID顯示這個確切的代碼。我的文本編輯器加載得很好,它工作得很好,但我似乎無法抓住實例。 data-wysihtml5在我首先啓動代碼時似乎並未添加爲屬性。

我試圖獲得當你點擊「引用」時它會引用帖子(我可以在稍後添加以獲取該上下文)到文本編輯器中。感謝您的幫助或指導!

+0

希望這仍然是活躍的,所以人們可以查看它..我仍然需要這方面的幫助:( – HaleyBuggs

+0

你的答覆在這裏沒有幫助你嗎?https://github.com/bootstrap-wysiwyg/bootstrap3-wysiwyg/issues/ 107 – Gaz

+0

礦已經有這個添加到它..它已經有了這個改變,所以我沒有辦法解決它。 – HaleyBuggs

回答

0

我有更新wysihtml5編輯器同樣的問題,這個解決它:

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

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