Kendo Multiselect值设置错误 [英] Kendo Multiselect value setting Bug
问题描述
我在使用剑道多重选择时遇到了这个奇怪的问题.
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/
问题复制
-
单击初始化列表" ,然后通过键盘将新标签添加到框中.
click "Init List" and then add new tag to the box by keyboard.
现在单击填充列表按钮. 所有值均未选中.或有时只选择了1个
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.
我在Chrome v32.0.1700.107 m中进行了测试
I tested in Chrome v32.0.1700.107 m
推荐答案
在多选中设置新值之前,应在tagObj.dataSource.filter({});
Before setting new values in a multiselect, you should clean the filter before tagObj.dataSource.filter({});
您的功能应该是:
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());
}
}
您的JSFiddle在此处进行了修改: http://jsfiddle.net/OnaBai/AgV52/2/
Your JSFiddle modified here: http://jsfiddle.net/OnaBai/AgV52/2/
这篇关于Kendo Multiselect值设置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!