Auto complete of JqueryUi

1

I'm not able to list my Json in the jqueryUI autocomplete. In the browser console I see that it is calling more does not show at the time when I append the append in LI.

$(function(){
    var mostraLista = "http://jsonplaceholder.typicode.com/users";
  		$.get(mostraLista, function(response){
		var dados = response;
		for(var i = 0; i < dados.length; i++){
			var tudoJ = dados[i];
			console.log(tudoJ.name);
			$("<li>").text(tudoJ.email).appendTo(".ui-corner-all");
		}
	});

  $("#tags").autocomplete({
  	source: mostraLista
  });	
});
    
asked by anonymous 23.12.2015 / 18:19

1 answer

1

The autocomplete needs to have the data already formatted. If you pass an array with what you need it will work. In the example below I map the data to create an array with only the names. And so in autocomplete it will fetch and automatically insert the required HTML.

$(function() {
    var url = "http://jsonplaceholder.typicode.com/users";
    $.get(url, function(response) {
        var nomes = response.map(function(pessoa){
        return pessoa.name;
        })
        $("#tags").autocomplete({
            source: nomes
        });
    });
});

jsFiddle: link

    
23.12.2015 / 18:26