Ho 2 .json contenenti dati [riparazioni] [clienti] e un codice che effettua una ricerca in entrambi typeahead.
Funziona, mi mostra i risultati per "categoria", ma da quello che vedo posso usare solo un campo del JSON ('reapir' o 'client')
Avrei necessità di andare a visitare la rispettiva pagina cliccando sul risultato: /repair/$id o /client/$id
Ho provato ad inserire la funzione e anche a definire un 'window.location.href =' che ovviamente non ha funzionato.
Se qualcuno riesce ad aiutarmi, ringrazio anticipatamente.
Documentazione: https://github.com/twitter/typeahead.js
codice:var KTTypeahead = function() { var search = function() { var repairsSearch = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('repair'), queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: 'settings/repairs.php' }); var clientsSearch = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('client'), queryTokenizer: Bloodhound.tokenizers.whitespace, prefetch: 'settings/clients.php' }); $('#search').typeahead({ highlight: true }, { name: 'repairs', display: 'repair', source: repairsSearch, templates: { header: '<h3 class=\"league-name text-info\" style=\"padding: 5px 15px; font-size: 1.2rem; margin:0;\">Riparazioni</h3>' } }, { name: 'clients', display: 'client', source: clientsSearch, templates: { header: '<h3 class=\"league-name text-primary\" style=\"padding: 5px 15px; font-size: 1.2rem; margin:0;\">Clienti</h3>' } }); } return { // public functions init: function() { search(); } }; }(); jQuery(document).ready(function() { KTTypeahead.init(); });

Ottima scelta
Rispondi quotando