如何在使用Html.Kendo()时编辑Jquery中的编辑器

时间:2013-03-15 14:59:11

标签: jquery telerik-mvc telerik-editor

我正在将Telerik Kendo UI编辑器用于可以发布到服务器的字段。

@( Html.Kendo().EditorFor(model => model.TickerContent)
                           .Name("TickerContent")
                           .Encode(true)
                           .HtmlAttributes(new { style = "width:100%;height:440px" }))

在与表单相同的页面上,我有一个我希望能够编辑的项目列表,因此我需要设置编辑器的值。演示代码使用以下代码来获取和设置编辑器的值:

<script>
    $(document).ready(function () {
        var editor = $("#Editor").data("kendoEditor");

        var setValue = function () {
            editor.value($("#value").val());
        };

        $("#get").click(function () {
            alert(editor.value());
        });

        $("#set").click(setValue);
    });
</script>

变量编辑器的值始终未定义。我的问题是如何获取和设置编辑器值?

我尝试了var editor = $(“#TickerContent”)。data(“kendoEditor”);但编辑仍未定义。

3 个答案:

答案 0 :(得分:1)

这里也是同样的问题,这就是我所做的:

对于html

@Html.TextAreaFor(model => model.TickerContent);

对于JS

    <script>
         $(function(){
            $("#TickerContent").kendoEditor().data("kendoEditor");
            var editor  = $("#TickerContent").data("kendoEditor");
         })
    </script>

然后“编辑器”未定义

答案 1 :(得分:0)

我认为您需要删除.Name(“TickerContent”)。我遇到过同样的问题。为什么,我不知道。

答案 2 :(得分:0)

要设置编辑器值,可以这样设置:

$("#Editor").data("kendoEditor").value($("#value").val());