I use Twitter Typeahead.js in a subcomponent in Ember, which I pass to the dataSource function (see below). This dataSource function requests a remote server. This request, which I would like to discuss in Ember, which does not seem to work.
Is this related to runloop? All I have to wrap?
import Ember from 'ember'; export default Ember.Component.extend({ dataResponse: [], dataSource: function () { var component = this; // function given to typeahead.js return function (query, cb) { var requestFunc = function () { var encQuery = encodeURIComponent(query); Ember.$.getJSON('/api/autocompletion?prefix=' + encQuery).then(function (result) { // save results component.set('dataResponse', result.autocompletion); // map results var mappedResult = Ember.$.map(result.autocompletion, function (item) { return { value: item }; }); cb(mappedResult); }); }; // this is not debounced, why? :| Ember.run.debounce(this, requestFunc, 500); // debounce by 500ms }; }.property() });
Note. I do not use Bloodhound with Typeahead.js since I need access to the results. At first, the custom solution was simpler.
source share