网站搜索

javascript - bootstrap wysihtml5 设置值不起作用


我有一个 wysihtml 编辑框,我想在 ajax 调用后填充它的值

$("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5();

function ModificaCategoria(id) {
    $.ajax({
                url: "Categorie.aspx/GetCategoria",
                type: 'POST',
                dataType: "json",
                data: JSON.stringify({ 'id': id }),
                contentType: 'application/json; charset=utf-8',
                cache: false,
                async: false,
                processdata: true,
                traditional: true,
                success: function (data) {
                    var c = data.d;
                        //we need to parse it to JSON 
                        c = $.parseJSON(c);
                        $('#<%=txtTitleCategoria.ClientID%>').val(c.Title);
                        $('#<%=txtDescrizioneBreveCategoria.ClientID%>').val(c.Descrizione);
                }
        });
}

我已经尝试过了

$('#<%=txtDescrizioneBreveCategoria.ClientID%>').contents().find('body').html('<b>New text</a>');

和与

$('#<%=txtDescrizioneBreveCategoria.ClientID%>').html(c.Descrizione);

和与

var editorObj = $("#<%=txtDescrizioneBreveCategoria.ClientID%>").data('wysihtml5');
var editor = editorObj.editor;
editor.setValue(c.DescrizioneBreve);

但是编辑器变量总是未定义,我正在使用 wysihtml5x v0.4.15,这里有链接

答案#1

你应该能够使用下面的方法达到相同的效果

$("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5();
window.describeEditor = window.editor;

然后你以后应该可以使用

describeEditor.setValue(c.DescrizioneBreve, true)

或使用

editorDescrizioneBreve.data("wysihtml5").editor.setValue(c.DescrizioneBreve, true);

其中 editorDescrizioneBreve 是由 $ ("#<%=txtDescrizioneBreveCategoria.ClientID%>").wysihtml5() 返回的对象

附注:解决方案基于 https://github.com/jhollingworth/bootstrap-wysihtml5/issues/52

答案#2

对我来说,这有效:

$('.wysihtml5-sandbox').contents().find('body').html(descr)

我的页面上只有一个 Wysihtml5,如果有多个,你需要使用更精确的选择器。