javascript - Issues with selectize.js and ajax -


in view have following code , i'm trying select box drop down values send callback unfortunately not work.

i following http://maxoffsky.com/code-blog/laravel-shop-tutorial-3-implementing-smart-search/ slight changes , there suite use case.

<script>      $(document).ready(function(){         var root = '{{url("/")}}';          $('#testselect').selectize({             valuefield: 'url',             labelfield: 'description',             searchfield: ['description'],             maxoptions: 10,             options: [],             create: true,             render: {                 option: function(data, escape) {                     return '<div>' + escape(data.description) + '</div>';                 }             },             optgroups: [                 {value: 'description', label: 'description'},             ],             load: function(query, callback) {                 if (!query.length) return callback();                 $.ajax({                     url: root+'/gettimecodes',                     type: 'get',                     datatype: 'json',                     data: {                         q: query                     },                     error: function() {                         callback();                     },                     success: function(res) {                         console.log(res.data) // prints data , good.                         var object = {description:"description"};                         var array = ["saab", "volvo", "bmw"];                         var json = {                             "data":[                                 {"description":"saab"},                                 {"description":"volvo"},                                 {"description":"bmw"}                             ]                         }                         // callback(array); // doesn't work. (array)                         // callback(object); // doesn't work (object)                         // callback(json); // doesn't work (json)                     }                 });             },         });     });  </script> 

if 1 point me in correct direction appreciated!

updated bashers recomendations.

            $('#testselect').selectize({             valuefield: 'description',             labelfield: 'description',             searchfield: ['description'],             maxoptions: 10,             options: [],             create: true,             render: {                 option: function(data, escape) {                     return '<div>' + escape(data.description) + '</div>';                 }             },             load: function(query, callback) {                 if (!query.length) return callback();                 $.ajax({                     url: '/gettimecodes',                     type: 'get',                     data: {                         q: query                     },                     error: function() {                         callback();                     },                     success: function(res) {                         callback(res.data)                     }                 });             },         }); 

the json returned in response

{"data":[{"description":"crushed blacks "},{"description":"crushed     blacks "},{"description":"example of crushed blacks"},{"description":"example of crushed blacks , video noise"},{"description":"example of heavily de-interlaced artfacts on footage during title sequence - source"}]} 

your valuefield not exist. url not property of object pass. change valuefield description. let me know more specific error if one. remove optgroups now. keep basic.


Comments