2012-04-10 14 views
4

Ich versuche, in ein bootstrap-wysihtml5-Editor-Objekt zuzugreifen. Ich tue dies auf diese Weise:Zugriff auf das bootstrap-wysihtml5-Editor-Objekt

$(document).ready(function() { 
    $('.someLink').live('click', function() { 
      var wysihtml5Editor = $('#textarea').wysihtml5().editor; 
      console.log('wysihtml5Editor: '+wysihtml5Editor); 
      wysihtml5Editor.composer.commands.exec("bold"); 
    }); 
}); 

Chrome Konsole kehrt:

> wysihtml5Editor: undefined 
> Uncaught TypeError: Cannot read property 'composer' of undefined 

So ist der Punkt.

Welcher Art ist der Zugang zu einem wysihtml5-Objekt?

Der Punkt von allem ist, fügen Sie einige HTML-Code in meine Textarea.

Antwort

9

Versuchen Sie folgendes:

$(document).ready(function() { 
    $('.someLink').live('click', function() { 
    $('#textarea').wysihtml5(); 
    var wysihtml5Editor = $("#textarea").data("wysihtml5").editor; 
    console.log('wysihtml5Editor: '+wysihtml5Editor); 
    // The following is important since wysihtml5 is initialized asynchronously 
    wysihtml5Editor.observe("load", function() { 
     wysihtml5Editor.composer.commands.exec("bold"); 
    }); 
    }); 
}); 
+0

danke sehr! – CROWD

+1

Vielen Dank! Das hat mir auch geholfen. –

Verwandte Themen