Kendo ui Multi Select使用值删除选定的元素 [英] Kendo ui Multi Select Remove Selected element using value
问题描述
我正在使用kendo ui多项选择
http://demos.kendoui.com/web/multiselect/events.html
我有这个代码
var data =
[
{ text: "Africa", value: "1" },
{ text: "Europe", value: "2" },
{ text: "Asia", value: "3" },
{ text: "North America", value: "4" },
{ text: "South America", value: "5" },
{ text: "Antarctica", value: "6" },
{ text: "Australia", value: "7" }
];
var multi = $("#select").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: data
}).data("kendoMultiSelect");
现在我可以使用它添加值
multi.value(["5", "3"]);
现在我要从所选值中删除
有什么方法可以使用value
或text
例如,如果我要删除5
,那么是否有像multi.remove(["5"]);
或其他任何删除方式?
要以编程方式从MultiSelect中删除元素,可以使用:
// Elements to be removed
var subtract = ["1", "5"];
// Get copy of current selected elements
var values = multi.value().slice();
// Remove elements from subtract
values = $.grep(values, function(a) {
return $.inArray(a, subtract) == -1;
});
// Clean filtering
multi.dataSource.filter({});
// Set new values
multi.value(values);
subtract
是要删除的元素(在此示例中为"1"和"5").
提示:要添加,您可以使用:
// Elements to add
var add = ["4", "5"];
// Get copy of current selected elements
var values = multi.value().slice();
// Merge withe elements to add
var merge = $.merge(values, add);
// Clean filtering
multi.dataSource.filter({});
// Remove duplicates and set them back
multi.value($.unique(merge));
此处的运行示例: http://jsfiddle.net/OnaBai/9WfGA/ >
I am using kendo ui multiple select
http://demos.kendoui.com/web/multiselect/events.html
i have this code
var data =
[
{ text: "Africa", value: "1" },
{ text: "Europe", value: "2" },
{ text: "Asia", value: "3" },
{ text: "North America", value: "4" },
{ text: "South America", value: "5" },
{ text: "Antarctica", value: "6" },
{ text: "Australia", value: "7" }
];
var multi = $("#select").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: data
}).data("kendoMultiSelect");
now i can add the values using this
multi.value(["5", "3"]);
now i want to remove from the selected values
is there any way to remove the values using value
or text
for example if i want to remove 5
then is there any method like multi.remove(["5"]);
or any other way to remove it???
For removing element from a MultiSelect programmatically, you can use:
// Elements to be removed
var subtract = ["1", "5"];
// Get copy of current selected elements
var values = multi.value().slice();
// Remove elements from subtract
values = $.grep(values, function(a) {
return $.inArray(a, subtract) == -1;
});
// Clean filtering
multi.dataSource.filter({});
// Set new values
multi.value(values);
Where subtract
are the elements to be removed (in this example "1" and "5").
TIP: For adding, you can use:
// Elements to add
var add = ["4", "5"];
// Get copy of current selected elements
var values = multi.value().slice();
// Merge withe elements to add
var merge = $.merge(values, add);
// Clean filtering
multi.dataSource.filter({});
// Remove duplicates and set them back
multi.value($.unique(merge));
Running example in here : http://jsfiddle.net/OnaBai/9WfGA/
这篇关于Kendo ui Multi Select使用值删除选定的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!