using countries json with selectize plugin

738 Views Asked by At

I'm sorry for the question it maybe easy but I tried many and many with no result, I can't understand the concept of using json with plugin selectize .. I'm trying to load json file contains countries, to display it in select field in my form. I found countries json file on github. this is my js code

$('select#country').selectize({
        valueField: 'item',
        labelField: 'item',
        options: 'countries.json'
    });

I read plugin usage documentation but i had confused. I need help example of using json or parsing json to object to use it with selectize plugin !

1

There are 1 best solutions below

0
On BEST ANSWER

If you have

$('select#country').selectize({
        valueField: 'id',
        labelField: 'country_name',
        options: 'countries.json'
    });

Then you can pass JSON values :

[{"id":"1","country_name":"Australia"},{"id":"2","country_name":"Belgium"} ]