- Home
- Forum
- JavaScript - EJ 2
- Get / Set item by value
Get / Set item by value
Hi all,
I have simple data source like this:
let ds = [
{
value: "value1",
text: "Value no 1"
},
{
value: "value2",
text: "Value no 2"
}
value: "value1",
text: "Value no 1"
},
{
value: "value2",
text: "Value no 2"
}
];
and I instantiate ej dropdownlist using that data source.
And then I want to select the item using the value (not the text).
This code does not work:
{
value: "value2"
}
But this code works:
{
value: "Value no 2"
}
Also getter, when I want to know what is the selected value, the .value is the same as the .text..
How I can achieve get/set using value not text?
Thank you.
SIGN IN To post a reply.
3 Replies
NP
Narayanasamy Panneer Selvam
Syncfusion Team
September 5, 2019 03:48 AM UTC
Hi Oka,
Greetings from Syncfusion support.
Based on the code, we are not clear whether you are using EJ1 or EJ2. As you have mentioned “*EJ DropDownList*”, we have prepared a sample with EJ1 DropDownList for setting and getting value. You need to map the value field so that this will work fine. You can get the selected value by getSelectedValue() method.
|
$(function () {
// declaration
ds = [
{
value: "value1",
text: "Value no 1"
},
{
value: "value2",
text: "Value no 2"
}
];
$('#bikeList').ejDropDownList({
dataSource: ds,
fields: { text: "text", value: "value" },
value: "value2"
});
});
function get() {
var ddlObj = $("#bikeList").data("ejDropDownList");
alert(ddlObj.getSelectedValue());
} |
Demo sample: https://jsplayground.syncfusion.com/jj5tcvyu
Please let us know if you have any concern on this.
Regards,
Narayanasamy P.
OS
Oka Sugandi
September 5, 2019 03:58 AM UTC
Thank you for your reply.
I am using EJ2 ES 5.
Would you like to give sample for EJ2 ES5?
Thank you.
NP
Narayanasamy Panneer Selvam
Syncfusion Team
September 5, 2019 01:13 PM UTC
Hi Oka,
Thanks for your update.
As per your request, we have prepared same sample in ej2.
Demo sample: https://stackblitz.com/edit/umcjfw?file=index.js
In this sample we can get the selected item using value property.
Please let us know if you need any further assistance on this.
Regards,
Narayanasamy P.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
OS Oka Sugandi
- Sep 3, 2019 10:43 AM UTC
- Sep 5, 2019 01:13 PM UTC