Kendo UI列表框显示重复项 [英] Kendo UI Listbox displaying duplicate items

查看:95
本文介绍了Kendo UI列表框显示重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kendo UI Listbox控件来显示项目.我通过指定一个javascript数组作为数据源来填充控件.

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.

这是页面标记.

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

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

这是我用来填充Kendo UI Listbox控件的javascript/JQuery.

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

这是我正在使用的DataSource数组.

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?

推荐答案

您似乎是在已经存在的实例上重新创建窗口小部件,这就是为什么它会重复这些项目. 查看.

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. 更改数据源的 data :

$("#selectedview").data("kendoListBox").dataSource.data(subscribers);

  • 设置 setDataSource 再次:

  • To set setDataSource again:

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

  • 这篇关于Kendo UI列表框显示重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆