最初加载localdatasource同时更改下载加载kendo中的服务器端数据

时间:2014-04-10 06:50:12

标签: kendo-ui kendo-dropdown

我的要求很小,但最初我想将Local DataSource加载到DropDownList。在更改DropDownlist时我想加载Server Side DataSource。如果有可能的话。

1 个答案:

答案 0 :(得分:1)

试试这个,

<div id='parentDiv'><div id='dropDown'></div></div>

<script type='text/javascript'>

 $(document).ready(function() {
                var data = [
                    { text: "Black", value: "1" },
                    { text: "Orange", value: "2" },
                    { text: "Grey", value: "3" }
                ];

                // create DropDownList from input HTML element
                $("#dropDown").kendoDropDownList({
                    dataTextField: "text",
                    dataValueField: "value",
                    dataSource: data,
                    index: 0,
                    change: onChange
                });

 function onChange(e)
 {

    var serachActionUrl="url";
    $.ajax({
        url: serachActionUrl,
        type: "POST",
        data: { Id: Id},
        traditional: true,
        success: function (result) {
         $('#dropDown').remove();
         $("<div id='dropDown'/>").appendTo('#parentDiv').kendoDropDownList({
              dataTextField: "text",
              dataValueField: "value",
              dataSource: result,
              index: 0,
              change: onChange
          });
        }
    });


</script>

从服务器端发送json数据