如何刷新KendoUI DropDownList?

Rod*_*ney 4 javascript asp.net-mvc telerik kendo-ui

我有一个需要更新的kendo ui网格.所以我有以下标记:

我调用以下脚本来填充下拉列表:

   // An Ajax call to load the selected hover into the controls
    $.ajax({
        type: 'POST',
        url: '/Reports/HoverManager/GetHoversForDropDown',
        data: { sectionId: sectionId },
        error: function(response){
            $('.hover-manager .error').html(response.responseText).fadeIn(500).delay(5000).fadeOut(500);
        },
        success: function(response){

            $('.hover-manager #hoverSelect').kendoDropDownList({  
                animation: false,
                dataTextField: "Name",
                dataValueField: "ID",
                dataSource: response.hovers,
                change: hoverDownDownChange,
            }).data('kendoDropDownList').value(hoverId);    

        }
    });
Run Code Online (Sandbox Code Playgroud)

一旦页面加载.我调用相同的脚本来刷新下拉列表.我在源代码中注意到数据源包含新数据但隐藏了下拉列表.

更新Kendo下拉列表的正确方法是什么?

Pet*_*bev 7

您只需要初始化一次kendo DropDownList,每次要刷新数据时都应该使用dataSource.data()方法.

就像是 :

$('#hoverSelect').kendoDropDownList({  
            animation: false,
            dataTextField: "Name",
            dataValueField: "ID",                
            change: hoverDownDownChange,
        }).data('kendoDropDownList').value(hoverId); 

$.ajax({
    type: 'POST',
    url: '/Reports/HoverManager/GetHoversForDropDown',
    data: { sectionId: sectionId },
    error: function(response){
        $('.hover-manager .error').html(response.responseText).fadeIn(500).delay(5000).fadeOut(500);
    },        success: function(response){

        $('#hoverSelect').data('kendoDropDownList').dataSource.data(response.hovers);    

    }
});
Run Code Online (Sandbox Code Playgroud)