Created
June 1, 2016 06:30
-
-
Save heanfig/7da5766f7c8c8550ed04e6727d672c5b to your computer and use it in GitHub Desktop.
load remote query typeahead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var states = new Bloodhound({ | |
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.num); }, | |
queryTokenizer: Bloodhound.tokenizers.whitespace, | |
remote: { | |
url: Metronic.getAJAXURL() + "general/general/BuscarCiudades?query=%QUERY", | |
filter: function (ciudades) { | |
return $.map(ciudades, function (ciudad) { | |
return { | |
num: ciudad.id_ciudad, | |
nombre: ciudad.ciudad_nombre.toLowerCase(), | |
nombredepartamento: ciudad.estado_nombre.toLowerCase() | |
}; | |
}); | |
} | |
}, | |
limit: 1000 | |
}); | |
states.initialize(); | |
$('#typeahead_ciudad').typeahead(null, { | |
display: 'nombre', | |
name: 'productos_UNSPSC', | |
source: states.ttAdapter(), | |
templates: { | |
empty: [ | |
'<div class="empty-message">', | |
'No se encontraron coincidencias con el criterio de búsqueda', | |
'</div>' | |
].join('\n'), | |
suggestion: Handlebars.compile('<div class="item-result" style="text-transform: capitalize;">{{nombre}}<div class="clase_placeholder">{{ nombredepartamento }}</div></div>') | |
} | |
}); | |
$('#typeahead_ciudad').on('typeahead:selected', function (e, suggestion, name) { | |
$scope.ingresardireccion.ciudad = suggestion.num; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment