Kendo UI Listbox displaying duplicate items

懵懂的女人 提交于 2020-01-16 08:26:07

问题


I'm using a Kendo UI Listbox control to display items. I'm populating the control by specifying a javascript array as the data source.

Here is the page markup.

<div>
  <select id="selectedview"></select> 
</div>

<script>
    $(document).ready(function () {
        $("#selectedview").kendoListBox();
    });
</script>

And here is the javascript / JQuery that I am using to populate the Kendo UI Listbox control.

var listBox = $("#selectedview").data("kendoListBox");
listBox.clearSelection();

$("#selectedview").kendoListBox({
    dataSource: subscribers
});

Here's the DataSource array that I am using.

When the control is displayed however the same two items are displayed multiple times in error.

What's going on and how do I fix this?


回答1:


You seem to be re-creating the widget over an already existent instance, that is why it is duplicating the items. Check this out.

If you want to update the list of an already created widget instance, try either:

  1. Change the DataSource's data:

    $("#selectedview").data("kendoListBox").dataSource.data(subscribers);
    
  2. To set setDataSource again:

    $("#selectedview").data("kendoListBox").setDataSource(new kendo.data.DataSource({ 
        data: subscribers
    });
    


来源:https://stackoverflow.com/questions/50763006/kendo-ui-listbox-displaying-duplicate-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!