我有一个需要更新的剑道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);
}
});
页面加载后。我调用相同的脚本来刷新下拉列表。我在源中注意到数据源包含新数据,但下拉列表是隐藏的。
更新剑道下拉列表的正确方法是什么?
你只需要初始化一次 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);
}
});