Kendo Multiselect value setting Bug

我的未来我决定 提交于 2019-12-05 03:26:10

问题


I having this weird problem with kendo multiselect.

<input id="addTags" /><br>
<input type="button" onclick="fillaList();" value="fill List" />
<input type="button" onclick="clearList();" value="Init List" />

var list=[{label:'tag1', value:'1'},
         {label:'tag9', value:'9'},
         {label:'tag8', value:'8'},
         {label:'tag7', value:'7'},
         {label:'tag6', value:'6'},
         {label:'tag5', value:'5'},
         {label:'tag4', value:'4'},
         {label:'tag3', value:'3'},
         {label:'tag2', value:'2'}];

function fillData(tagIds){ 

    var tagObj = $("#addTags").data("kendoMultiSelect");
    if (tagObj == undefined) { // if not loaded
        $("#addTags").kendoMultiSelect({
            dataTextField: "label",
            dataValueField: "value",
            dataSource: list,
            value: tagIds, placeholder: "Select from list",
            change: function() {
                // change
            }
        });
    } else { // if already loaded only change the values.
        tagObj.value(tagIds);
        console.log(tagIds);
        console.log(tagObj.value());
    }
}
function fillaList(){
    var tagIds=[1,2,3];
    fillData(tagIds);
}
function clearList(){
    fillData([]);
}

http://jsfiddle.net/ruchan/AgV52/1/

Problem Replication

  • click "Init List" and then add new tag to the box by keyboard.

  • now click fill List button. all The values are not being selected. or sometimes only 1 is selected

this problem is not there when selecting by mouse.

I tested in Chrome v32.0.1700.107 m


回答1:


Before setting new values in a multiselect, you should clean the filter before tagObj.dataSource.filter({});

Your function should be:

function fillData(tagIds){ 

    var tagObj = $("#addTags").data("kendoMultiSelect");
    if (tagObj == undefined) { // if not loaded
        $("#addTags").kendoMultiSelect({
            dataTextField: "label",
            dataValueField: "value",
            dataSource: list,
            value: tagIds, placeholder: "Select from list",
            change: function() {
                // change
            }
        });
    } else { // if already loaded only change the values.
        // Clean DataSource filter before setting new values
        tagObj.dataSource.filter({});
        tagObj.value(tagIds);
        console.log(tagIds);
        console.log(tagObj.value());
    }
}

Your JSFiddle modified here: http://jsfiddle.net/OnaBai/AgV52/2/



来源:https://stackoverflow.com/questions/22010796/kendo-multiselect-value-setting-bug

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