running-coder / jquery-typeahead

Javascript Typeahead (autocomplete) plugin with more than 50 options and callbacks.
http://www.runningcoder.org/jquerytypeahead/
MIT License
544 stars 121 forks source link

The data pulled from ajax is not showing in the typeahead results #272

Closed anand2316 closed 7 years ago

anand2316 commented 7 years ago

Hello, I am using the typeahead feature in the following way. Typeahead shows the initialized list and also items added through push but not items added through AJAX. Here is the code, any help is appreciated.

 $(function(){

 var currencies = [" ", "Rang", "Subs", "super"];
 var currencies1 = [" ", "Samy", "MR", "happy"];

 currencies.push("elephant");
 currencies1.push("aane");

        var path = "https://api.appery.io/rest/1/code/eba6bc3e-0d8f-48df-9186-2b173fa7ee92/exec";
        $.getJSON(path, {}, function (data) {
        $.each(data, function (i, field) {
            currencies.push("pet"+i);
            currencies1.push("good"+i);
          }); 
    }); 

  $('#autocomplete').autocomplete({
     lookup: currencies,
    onSelect: function (suggestion) {
      /*  var thehtml = '<strong>Currency Name:</strong> ' + suggestion.value + ' <br> <strong>Symbol:</strong> ' + currenciesG[currenciesG.indexOf(suggestion.value)];*/
    /*  var thehtml = '<strong>Currency Name:</strong> ' + suggestion.value + ' <br> <strong>Symbol:</strong> ' + suggestion.data; */
      $('#outputcontent').html(thehtml);
       var a = document.getElementById("playerName");
        a.value = suggestion.value;
        var b = document.getElementById("playerId");
        b.value = suggestion;
    }
  });
 });
running-coder commented 7 years ago

hey @anand2316 looks like you posted on the wrong project, Typeahead doesn't initialize like this