lundi 12 mai 2014

How can I programatically change a jquery select2 item?


Vote count:

0




I have a dropdown on an asp.net-mvc page:



<% = Html.DropDownList("PersonId", Model.DevManagers,
new { @id = "PersonId", @class = "searchDropdown" })%>


and I am converting it to use jquery select2 like this



$(".searchDropdown").select2({
width: "500px",
allowClear: true
});


the issue is that if i try then changing the underlying select value like this:



$('#PersonId').val(data.TechOwnerId);


the select2 widget doesn't change the selecteditem.


What is the correct way to update the jquery select2 selected item programmatically?



asked 1 min ago

leora

4,542

1 Answer



Vote count:

0




You need to do it like this -



$('#PersonId').select2("val",data.TechOwnerId);


answered 18 secs ago





1 commentaire: