Как добавить результат автозаполнения в таблицу? - PullRequest
0 голосов
/ 11 июня 2019

Я пытаюсь построить таблицу с результатами, которые я получил в форме автозаполнения. Я попытался добавить функцию щелчка внутри response, но мне это удалось, напечатать предупреждение с более чем необходимой информацией.

Файл JS

 $(document).ready(function(){
    $("#autocomplete").autocomplete({
      source: function(request,response){
        $.ajax({      
          type: "POST",
          url: "{{url_for('auto')}}",
          data: $('#formautocomplete').serialize(),

          beforeSend: function(){
           //$('#autocomplete').addClass('ui-autocomplete-loading');
          },

          success: function(data){
            response($.map(data,function(item){

              return {
                label: item[0]+' - '+item[1], 
                value: item[0] 
              }
               //Put onclick function here printing an alert, but
              // was printed all data, no just one.

            }));                          
          }

        });
      }
    });
  });

HTML

 <div class="col">
     <form id="formautocomplete" method="POST" action="#"> 
      <input  class="autocomplete" id="autocomplete" name="autocomplete" placeholder="ID" type="text">
      <button type="button" id="buttonAdd" class="btn btn-outline-secondary btn-sm">Add</button>
     </form> 
    </div>


 <table class="table table-sm">
        <thead class="thead-default">
          <th>Id</th>
          <th>Name</th>
          <th>Type</th>
        </thead>
        <tbody>
         //Results here
        </tbody>
      </table>
...