SumoSelect rejecting array

104 views Asked by At

im trying to inplement this array to jQuery SumoSelect librery

var devices= [{

         text: "iphone",
         value:"iphone"

      },
      {
        text: "android",
        value:"android"

     },
     {
        text: "mac",
        value:"mac"

     }]

im reading it with the following code

$("select").SumoSelect({search: true, searchText: 'search'});

for(var i in devices){
    $(".type-vehicle").append("<option>"+devices[i].text+"</option>");
}

it shows me an empty select but if i just do it without SumoSelect librery it works perfectly, i mean it shows me the select inputs with the 3 devices.

do you guys know what`s going on? why is rejecting me the array with the SumoSelect librery? thanks!

1

There are 1 answers

0
ProEvilz On BEST ANSWER

You need to populate the select box first, then invoke SumoSelect. You almost had it!

var devices = [{

    text: "iphone",
    value: "iphone"

  },
  {
    text: "android",
    value: "android"

  },
  {
    text: "mac",
    value: "mac"

  }
]
for(var i in devices){
    $("select").append("<option>"+devices[i].text+"</option>");
}
$("select").SumoSelect({search: true, searchText: 'search'});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.0.2/sumoselect.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.0.2/jquery.sumoselect.min.js"></script>

<select id="select">
<option>Test</option>
</select>