Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kendo ui 如何优化包含5000项的剑道UI组合框的数据源?_Kendo Ui - Fatal编程技术网

Kendo ui 如何优化包含5000项的剑道UI组合框的数据源?

Kendo ui 如何优化包含5000项的剑道UI组合框的数据源?,kendo-ui,Kendo Ui,在我的测试->中,KendoUI组合框无法运行5000个项目,我如何在不调用服务器端数据源的情况下使其工作,或者这是KendoUI的限制 HTML <h3>T-shirt Fabric</h3> <input id="fabric" placeholder="Select fabric..." /> T恤面料 JS /** * Returns a random integer between min and max * Using Math.round

在我的测试->中,KendoUI组合框无法运行5000个项目,我如何在不调用服务器端数据源的情况下使其工作,或者这是KendoUI的限制

HTML

<h3>T-shirt Fabric</h3>
<input id="fabric" placeholder="Select fabric..." />
T恤面料
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
    });
});
/**
*返回最小值和最大值之间的随机整数
*使用Math.round()将得到非均匀分布!
*/
函数getRandomInt(最小值、最大值){
返回Math.floor(Math.random()*(max-min+1))+min;
}
$(文档).ready(函数(){
var superData=[]
,数据=[
{文本:“棉花”,值:“1”},
{文本:“聚酯”,值:“2”},
{文本:“棉/涤纶”,值:“3”},
{文本:“罗纹针织”,值:“4”}
];

对于(var\u i=0;\u i问题不在剑道UI组合框中,而是在您的循环中。您是否检查了它的功能(而不是您希望它执行的功能)?我想说,这是一个错误,因为
data[getRandomInt(0,data.length-1)]
不返回新元素,而是一个引用,因此您要添加“\u i”对相同的5个元素多次创建一个非常长的字符串

请尝试以下方法:

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);
}
for(var\u i=0;\u i<5000;\u i++){
var randomEntry=数据[getRandomInt(0,data.length-1)];
var newEntry={
text:randomEntry.text+'-'+\u i,
值:randomEntry.value+=\u i
};
superData.push(newEntry);
}

在这里检查Fiddle的修改版本:

JSFiddle链接已断开