2013-03-15 72 views
0

我使用Telerik Kendo UI編輯器可以發佈到服務器的字段。如何在使用Html.Kendo()時在Jquery中選擇編輯器EditorFor

@(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」);但編輯仍然未定義。

+0

檢查編輯器的「id」HTML屬性(在最終輸出中)。 – 2013-03-20 09:49:16

回答

0

我認爲你需要刪除.Name(「TickerContent」)。我遇到過同樣的問題。爲什麼,我不知道。

1

這裏同樣的問題,這裏是我做過什麼:

對於HTML

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

對於JS

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

那麼 「編輯」 不是未定義

相關問題