0
I have the following file gulpfile.js build, to generate the files css
and js
. He’s generating me two files:
$('#instituicao').autocomplete({
source: function (request, response) {
$.getJSON("/path/ajax", { q: request }, function(result) {
response($.map(result, function(item) {
console.log(item);
return item.nome;
}));
});
},
minLength: 5,
delay: 100
});
When I type, the object is printed on the console:
Example of JSON
of Objeto
charged:
[{"id":"7","nome":"EEEF EURIDICE LOPES PEDROSO","endereco":"aqui vir\u00e1 o endere\u00e7o"},{"id":"10","nome":"EEEFM JUSCELINO KUBITSCHEK DE OLIVEIRA","endereco":"aqui vir\u00e1 o endere\u00e7o"},{"id":"20","nome":"EEEF TANCREDO DE ALMEIDA NEVES","endereco":"aqui vir\u00e1 o endere\u00e7o"},{"id":"21","nome":"EEEFM PADRE EZEQUIEL RAMIN","endereco":"aqui vir\u00e1 o endere\u00e7o"}]
But not in the view autocomplete listing box.
<div class="form-group">
<input type="text" autocomplete="off" id="instituicao" name="instituicao"
class="form-control" placeholder="Nome da Instituição de ensino">
</div>
What I’m doing wrong?
PS: I know it’s not CSS
, because when I send the object this way it works:
var data = [{"id":"7","nome":"EEEF EURIDICE LOPES PEDROSO","endereco":"aqui vir\u00e1 o endere\u00e7o"},{"id":"10","nome":"EEEFM JUSCELINO KUBITSCHEK DE OLIVEIRA","endereco":"aqui vir\u00e1 o endere\u00e7o"},{"id":"20","nome":"EEEF TANCREDO DE ALMEIDA NEVES","endereco":"aqui vir\u00e1 o endere\u00e7o"},{"id":"21","nome":"EEEFM PADRE EZEQUIEL RAMIN","endereco":"aqui vir\u00e1 o endere\u00e7o"}];
$('#instituicao').autocomplete({
valueKey:'nome',
source: [data],
minLength: 5,
delay: 100
});
Is the problem in this part
$.map(result, function(item) {
 console.log(item);
 return item.nome;

 })
? Is it jquery-ui right? See if this helps http://answall.com/a/175148/3635– Guilherme Nascimento
What is this autocomplete? Have you seen in the documentation what format of the JSON object it expects? because I find it very unlikely that he will accept values with the key "name"(English) or a list of objects containing all attributes of the entity.
– mau humor
I’m wearing this: jquery-autocomplete
– Ivan Ferrer
@Ivanferrer I think instead of
{ q: request }
, the correct would be{ q: request.term }
, test the two possibilities of the answer– Guilherme Nascimento
Here’s more about the documentation .
– Ivan Ferrer