Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

82
Visualizações
How to add a tags to autocomplete - Jquery

I have an autocomplete drop down and i am trying to add a tags to the list. When i populate the availableTags array and run the project, it works fine as below

File.JS

var availableTags = [];
$(document).ready(function(){
$(function() {
    $( "#search-product" ).autocomplete({
      source: availableTags     
    }
    });
  });  
});


function getItems(token,id)
{  
     $.ajax({
        url: "/get/product/items",
        type: "POST",
        data: {
            _token: token,
            id:id,
        },
        success: (dataResult) => {
            availableTags.length = 0
            $.each(dataResult, function(index,products) {
              
               availableTags.push(products.name,products.price);

              }); 
        },
    });
}

Is there a way i can populate the the ul list with my a tags as below. This is what i have tried and when i run the project, it returns empty list.

Is there something i am doing wrong ?

JS

 function getItems(token,id)
    {  
         $.ajax({
            url: "/get/product/items",
            type: "POST",
            data: {
                _token: token,
                id:id,
            },
            success: (dataResult) => {
                availableTags.length = 0
                $.each(dataResult, function(index,products) {
                  
           availableTags.push( $(".ui-autocomplete").append('<li class="ui-menu-item" role="presentation"><a class="ui-corner-all" tabindex="-1">Apple & Samsung</a></li>'));
    
                  }); 
            },
        });
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have missing some syntax here:

var availableTags = [];
$(document).ready(function(){
    $( function() {
        $( "#search-product" ).autocomplete({
          source: availableTags
        });
    } );
});

In Success call back:

success: (dataResult) => {
    availableTags.length = 0;
    $.each(dataResult, function(index,products) {
       availableTags.push(products.name,products.price);
    });
    $("#search-product").autocomplete({
      source: availableTags
   });
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda