Kendo ui Multi Select 使用值删除选定元素 [英] Kendo ui Multi Select Remove Selected element using value
问题描述
我正在使用剑道ui多选
http://demos.kendoui.com/web/multiselect/events.html
我有这个代码
var 数据 =[{文字:非洲",价值:1"},{文字:欧洲",价值:2"},{文字:亚洲",价值:3"},{ 文字:北美",值:4"},{ 文字:南美洲",值:5"},{ 文字:南极洲",值:6"},{ 文字:澳大利亚",值:7"}];var multi = $("#select").kendoMultiSelect({数据文本字段:文本",数据值字段:值",数据来源:数据}).data("kendoMultiSelect");
现在我可以使用这个添加值
multi.value(["5", "3"]);
现在我想从选定的值中删除
有什么方法可以使用 value
或 text
例如,如果我想删除 5
那么有没有像 multi.remove(["5"]);
或任何其他方式删除它???
要以编程方式从 MultiSelect 中删除元素,您可以使用:
//要删除的元素var 减法 = ["1", "5"];//获取当前选中元素的副本var values = multi.value().slice();//从减法中删除元素values = $.grep(values, function(a) {返回 $.inArray(a, 减法) == -1;});//清洁过滤multi.dataSource.filter({});//设置新值多值(值);
其中 subtract
是要删除的元素(在本例中为1"和5").
提示:要添加,您可以使用:
//要添加的元素var add = ["4", "5"];//获取当前选中元素的副本var values = multi.value().slice();//合并要添加的元素var merge = $.merge(values, add);//清洁过滤multi.dataSource.filter({});//删除重复项并重新设置它们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屋!