$Categorias = [
[
'id' => 1,
'tipo' => 'Categoria''<b>Categoria</b>',
'value' => 'Carros'
],
[
'id' => 2,
'tipo' => 'Categoria''<b>Categoria</b>',
'value' => 'Motos'
]
];
echo json_encode($Categorias);
$( "#campo-busca" ).autocomplete({
minLength: 0,
source: 'autocomplete.php',
focus: function( event, ui ) {
$( "#campo-busca" ).val( ui.item.value );
return false;
},
select: function( event, ui ) {
$( "#campo-busca" ).val(ui.item.value);
return false;
}
})
.autocomplete( "instance" )._renderItem = function( ul, item ) {
return $( "<li>" )
.data("item.autocomplete", item)
.append( "<div><b>"+item"<div>"+item.tipo+": </b> " + item.value + "</div>")
.appendTo( ul );
};
var categorias = [
{
id: 1,
tipo: 'Categoria''<b>Categoria</b>',
value: 'Imóvel'
},
{
id: 2,
tipo: 'Categoria''<b>Categoria</b>',
value: 'Móveis'
},
{
id: 3,
tipo: 'Categoria''<b>Categoria</b>',
value: 'Carros'
},
{
id: 4,
tipo: 'Categoria''<b>Categoria</b>',
value: 'Motos'
}
];
$( "#campo-busca" ).autocomplete({
minLength: 0,
source: categorias,
focus: function( event, ui ) {
$( "#campo-busca" ).val( ui.item.value );
return false;
},
select: function( event, ui ) {
$( "#campo-busca" ).val(ui.item.value);
return false;
}
})
.autocomplete( "instance" )._renderItem = function( ul, item ) {
return $( "<li>" )
.data("item.autocomplete", item)
.append( "<div><b>"+item"<div>"+item.tipo+": </b> " +"+ item.value + "</div>")
.appendTo( ul );
};
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input type="text" id="campo-busca">