Reputation: 814
I have converted the kendo dropdownlist into kendo multiselect.
Dropdownlist contains 2 items:
$("#btnSendFlow").click(function () {
debugger;
var FlowData_array = [];
//var ROLECODE = $("#DDRolecode").val().trim();---For dropdownlist output: "D"
var ROLECODE = $("#DDRolecode").data("kendoMultiSelect").value();//added by chetan for multiselect output: "D" "U"
// var MPID = $("#DDRolecode").data("kendoDropDownList").text().split('-');---for dropdownlist output: (3)["D","UDMS","TMA Data Mgmt System"]
var MPID = $("#DDRolecode").data("kendoMultiSelect").value().split('-');//added for multiselect(How to do For multiple selected items?)-->
output should be like:
(3)["D","UDMS","TMA Data Mgmt System"]
(3)["U","TDMS","SMA Mgmt System"]
.....
.....
}
Commented lines is for Dropdownlist.
Output should be like for var MPID:
(3)["D","UDMS","TMA Data Mgmt System"]
(3)["U","TDMS","SMA Mgmt System"]
Upvotes: 2
Views: 4956
Reputation: 814
The Below code worked for me:
var control = $("#DDRolecode").data("kendoMultiSelect");
var selectedDataItems = control.dataItems();
//// create an array that only contains the selected ids
var MPID = [];
$(selectedDataItems).each(function () {
MPID.push(this.Name.split('-')); // you can access any property on your model here
});
console.log(MPID);
Upvotes: 2
Reputation: 21465
You can do like:
var selectedValues = $("#DDRolecode").data("kendoMultiSelect").value().map(item => item.split("-"));
The result will be:
Upvotes: 2
Reputation: 4497
You need to use the dataItems
method on the multiselect to get the underlying selected dataItems.
so all you should need to do is change your code from:
var MPID = $("#DDRolecode").data("kendoMultiSelect").value().split('-')
to:
var MPID = $("#DDRolecode").data("kendoMultiSelect").dataItems();
So this will give you an array of dataItems that you have selected. So if you need to only have the id then either change the value mapping
to valuePrimitive:true
or map the returning dataItems to the array list you need.
I have included a dojo showing how to get the items: https://dojo.telerik.com/ILEvITUQ
This is taken from the api demo dojo for multiselects but I have changed the Get Values
button to map the items to their values only and also stringifying the dataItems array.
Upvotes: 3