javascript - Populate Materialize autocomplete with json data -


i'm building little website project , i've been searching hours how populate autocomplete input using materialize plugin. i'm not familiar json or ajax i'm in pain doing it. original example doc comes static data :

$('input.autocomplete').autocomplete({ data: {   "apple": null,   "microsoft": null,   "google": 'http://placehold.it/250x250' }, limit: 20, // max amount of results can shown @ once. default: infinity. onautocomplete: function(val) {   // callback function when value autcompleted. }, minlength: 1, // minimum length of input autocomplete start. default: 1. }); 

my wish dynamic data database. i'm using php code so:

<?php         $query = $arg;         echo $query;          $json_output = array();         $reponse = $bdd->query("select cpnom competence cpnom ". $query);          while ($donnees = $reponse->fetch()) {                      $json_output[] = $donnees[0]. ": null";                         }          return json_encode($json_output); ?> 

i'm assuming code working because displays ["java":null, "js":null, "c":null] match database datas. idea how put json data in data argument instead of static names?

data: {   "apple": null,   "microsoft": null,   "google": 'http://placehold.it/250x250' } 

thank time!

  var data_2 = json.parse(sessionstorage.getitem('key_1'));        $(function() {          $('input.autocomplete').autocomplete({          data: data_2,        limit: 20, // max amount of results can shown @ once. default: infinity.      onautocomplete: function(val) {          // callback function when value autcompleted.      },      minlength: 2 // minimum length of input autocomplete start. default: 1.          });      });


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -