I have a JSON list of SelectListItems that I grab:
new SelectListItem
{
Text = item.Name,
Value = item.Id.ToString(),
Selected = item.Id.Equals(userId)
}).ToList();
Then this list is connected to a dropdown menu with JQuery:
$.Ajax call for an object above goes here...
function (data) {
data= $.map(data, function (item, a) {
return "<option value=" + item.Value + ">" + item.Text + "</option>";
});
$("#edit-user-list").html(data.join(""));
This works and populates my list just fine.
I can’t figure out syntax how to indicate my SELECTED item though!
Can you guys help me out ?
How with this JQuery can I indicate the selected item that’s indicated in the passed in JSON collection of items?
Thank you
1 Answer