简体   繁体   English

如何刷新KendoUI DropDownList?

[英]How to refresh a KendoUI DropDownList?

I have a kendo ui grid that i need to update. 我有一个需要更新的kendo ui网格。 So I have the following Mark-up: 所以我有以下标记:

I call the following script to populate the dropdownlist: 我调用以下脚本来填充下拉列表:

   // 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);    

        }
    });

Once the page loads. 一旦页面加载。 I call the same script to refresh the Drop Down List. 我调用相同的脚本来刷新下拉列表。 I've noticed in the source that the data source contains the new data but the drop down list is hidden. 我在源代码中注意到数据源包含新数据但隐藏了下拉列表。

What is the correct way to update the Kendo Drop Down List? 更新Kendo下拉列表的正确方法是什么?

You need to initialize the kendo DropDownList only once and each time you want to refresh the data you should use the dataSource.data() method. 您只需要初始化一次kendo DropDownList,每次要刷新数据时都应该使用dataSource.data()方法。

Something like : 就像是 :

$('#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);    

    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM