问题
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:
Change the DataSource's data:
$("#selectedview").data("kendoListBox").dataSource.data(subscribers);
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