0

I have used below code for set selected values into select2() but it not working when i am getting values dynamic from ajax. If a added static values then it is working fine. So help me about this. Below i added my code in that first one working and second one not.

I got the values of [response['pictoGramArr'] this from ajax is "GHS02","GHS04"

var arr = ["GHS04","GHS09"];
$("#ing_pictogram").select2("val", arr);

$("#ing_pictogram").select2("val", [response['pictoGramArr']]);

There is no any error in console, so why not working?

kishan
  • 11
  • 4
  • Maybe [this](https://stackoverflow.com/a/35131804/863110) could help. – Mosh Feu Oct 24 '19 at 08:22
  • @Mosh Feu in this same problem as i faced working for static value but not for dynamic which i mentioned. – kishan Oct 24 '19 at 08:28
  • What exactly is the value of `response['pictoGramArr']` (you've included a value, but with a typo)? You're then putting it in an array, so would be the same as `$("#ing_pictogram").select2("val", [arr]);` - which probably then won't work either. Try `$("#ing_pictogram").select2("val", response['pictoGramArr']);` – freedomn-m Oct 24 '19 at 08:56

0 Answers0