javascript - Angularjs app using autocomplete.js and reading from multiple Algolia sources not working -
i'm trying implement autocomplete functionality using angularjs , algolia's autocomplete.js 2 sources (indexes) algolia.
the second source autocomplete works fine, address autocomplete works first letter/number typed. type second character, address listings disappear. if swap 2 sources, address works fine, , zipcode works first letter/number.
additionally, when doing search, console.log(address); displays proper address that's being searched for, it's not displaying in autocomplete results.
here's gif of in action: http://d.pr/i/2gce
$scope.getdatasets = function() { return [{ source: algolia.sources.hits(settings.replica, { hitsperpage: 5 }), displaykey: 'address', name: 'address', templates: { suggestion: function(suggestion) { var address = '<span class="address">' + suggestion._highlightresult.address.value; if(suggestion.aptmnt) { address += ', unit ' +suggestion.aptmnt + '</span> | '; } else { address +='</span> | '; } address += '<span>' + suggestion.totbdrms + ' beds </span> | ' + '<span>' + suggestion.totbaths + ' bath asdf </span> | ' + ' <span> $' + cleanprice(suggestion.price) + '</span>'; console.log(address); return address; } } },{ source: algolia.sources.hits(settings.zipcode, { hitsperpage: 5 }), displaykey: 'zipcode', name: 'zipcode', templates: { suggestion: function(suggestion) { var zipcode = '<span class="zipcode">' + suggestion.zipcode + '</span>'; return zipcode; } } }] }; i'm using
jquery - v1.12.4 angularjs - 1.6.1 algoliasearch.angular.min.js - v3 algoliasearch.helper.min.js - v2.18.0 autocomplete.angular.min.js - v0.28.1 angular-ui-router.js - v0.4.2
ok, found workaround. never angular version of autocomplete work. additionally, when console.log(o); constructor function function dataset(o) {} inside autocomplete.angular.js, logging out twice. not sure if issue...but normal autocomplete.js isn't logging out twice.
since swapping on autocomplete.j, autocomplete has been working great. here's code i'm using:
autocomplete('#quicksearch', { hint: false, debug: true, openonfocus: true }, [ { source: autocomplete.sources.hits(settings.replica, { hitsperpage: 5 }), displaykey: 'address', name: 'address', templates: { suggestion: function(suggestion) { var address = '<span class="address">' + suggestion._highlightresult.address.value; if(suggestion.aptmnt) { address += ', unit ' +suggestion.aptmnt + '</span> | '; } else { address +='</span> | '; } address += '<span>' + suggestion.totbdrms + ' beds </span> | ' + '<span>' + suggestion.totbaths + ' bath </span> | ' + ' <span> $' + suggestion.price + '</span>'; return address; } } },{ source: autocomplete.sources.hits(settings.zipcode, { hitsperpage: 5 }), displaykey: 'zipcode', name: 'zipcode', templates: { suggestion: function(suggestion) { var zipcode = '<span class="zipcode">' + suggestion.zipcode + '</span>'; return zipcode; } } } ]);
Comments
Post a Comment