简体   繁体   English

如何为5000个项目优化Kendo UI Combobox的数据源?

[英]How can I optimize datasource for Kendo UI Combobox with 5000 items?

In my test -> http://jsfiddle.net/olragon/642c4/12/ , KendoUI Combobox cannot run with 5000 items, how can I make it work without calling severside data source or this is limit of KendoUI? 在我的测试 - > http://jsfiddle.net/olragon/642c4/12/中 ,KendoUI Combobox无法运行5000项,如何在不调用severside数据源的情况下使其工作,或者这是KendoUI的限制?

HTML HTML

<h3>T-shirt Fabric</h3>
<input id="fabric" placeholder="Select fabric..." />

JS JS

/**
 * Returns a random integer between min and max
 * Using Math.round() will give you a non-uniform distribution!
 */
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

$(document).ready(function() {
    var superData = []
    ,   data = [
            { text: "Cotton", value: "1" },
            { text: "Polyester", value: "2" },
            { text: "Cotton/Polyester", value: "3" },
            { text: "Rib Knit", value: "4" }
        ];

    for(var _i=0; _i<5000; _i++) {
        var randomEntry = data[getRandomInt(0,data.length-1)];
        randomEntry.text += '-' + _i;
        randomEntry.value += _i;
        superData.push(randomEntry);
    }

    // create ComboBox from input HTML element
    $("#fabric").kendoComboBox({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: superData,
        filter: "contains",
        suggest: true,
        index: 3
    });
});

Update 更新

The problem is not in Kendo UI ComboBox but in your loop. 问题不在于Kendo UI ComboBox,而是在你的循环中。 Did you check what it does (not what you want it to do)? 你检查它做了什么(不是你想要它做什么)? I would say that there is an error since data[getRandomInt(0,data.length-1)] does not return a new element but a reference so you are appending "_i" to the same 5 elements many times building up a very long string. 我会说有一个错误,因为data[getRandomInt(0,data.length-1)]没有返回一个新元素而是一个引用,所以你将“_i”追加到相同的5个元素很多次构建一个很长的串。

Try this instead: 试试这个:

for (var _i = 0; _i < 5000; _i++) {
    var randomEntry = data[getRandomInt(0, data.length - 1)];
    var newEntry = {
        text: randomEntry.text + '-' + _i,
        value            : randomEntry.value += _i
    };
    superData.push(newEntry);
}

Check the modified version of the Fiddle here: http://jsfiddle.net/OnaBai/642c4/14/ 在这里查看小提琴的修改版本: http//jsfiddle.net/OnaBai/642c4/14/

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

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