0

I've got the script below. I've noticed that the fetching of data works perfectly (verified by console.log(response), showing precisely what's supposed to be fetched). However, in the list of possible options that displays, only some of them are shown. Sometime it's all of them, sometimes a few or even none. I can't see any system in it.

var users = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.whitespace,
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  //prefetch: { url: "/Worker/HintUser", cache: false, ttl: 15000 },
  remote: {
    wildcard: 'partial',
    rateLimitWait: 100,
    url: "/Worker/HintUser?input=partial",
    transform: function (response) { console.log(response); return response; }
  }
});

$("#remoteFetch").typeahead(
{ hint: true, highlight: true, minLength: 1 },
{ name: 'users', source: users });

I've tried using and skipping prefetch, not keeping the cache etc. Same result all the time. What am I doing wrong?

I've found quite a few examples showing how it's working but I fail to see the relevant difference. Or perhaps missing a nice trick they apply.

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • What does your typeahead initialization look like? – trenthaynes May 03 '16 at 21:13
  • Sorry, it got cut off from the other post. Please view the completed version. – Konrad Viltersten May 03 '16 at 21:28
  • I would try specifying the datumTokenizer. – trenthaynes May 03 '16 at 21:30
  • Please keep in mind that this tech is fairly new and the number of explanations is scarce. I'm not even sure what *datumTokenizer* does. It splits something based on a regex looking for spaces but when and why... I don't know. Would you care to suggest a simple implementation of it? Along with some explanation as to what the *datum* is and why we want to *tokenize* it, please? – Konrad Viltersten May 03 '16 at 21:33
  • I don't quite understand just how the datumTokenizer works, only that in certain instances the absence seems to have a negative effect on the results. What does `response` look like (because that will decide on how I would implement it)? – trenthaynes May 03 '16 at 21:40
  • 1
    [best explanation I've found](https://github.com/twitter/typeahead.js/blob/master/doc/migration/0.10.0.md#tokenization-methods-must-be-provided) – trenthaynes May 03 '16 at 21:46
  • At the moment, the response is an array of string like this *["donkey","monkey"]* andit shows as expected. The fold-out options to pick from, however, don't show all the elements. And sometimes they show old hints (not in the array) like this: *monkey/donkey/banana*. Please note that in the future I'd prefer to return a bunch of objects instead, in the results, but that's for another chapter. – Konrad Viltersten May 04 '16 at 12:33
  • can we continue this in chat? – trenthaynes May 04 '16 at 13:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111009/discussion-between-whipdancer-and-konrad-viltersten). – trenthaynes May 04 '16 at 13:43

0 Answers0