How to use Typeahead.js 0.10 step-by-step / remote / prefetch / local

后端 未结 3 2005
半阙折子戏
半阙折子戏 2021-02-01 01:15
  • POST for Twitter Typeahead

I have been for 2 days now, trying to understand and have a clear picture on how to use /manage typeahead.js 0.10 in order to use

相关标签:
3条回答
  • 2021-02-01 01:42

    I just spent some days trying to get this to work my self, and I totally agree that its not intuitive. In particular there was one thing on the typeahead page about Bloodhound that try as I might just didn't work. For example the following line:

    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value') -- would always yield an error because obj didnt exist.

    For the datumTokenizer use the following form(where "DisplayText" is the name of the property in your object that contains the text that will be displayed):

    function (d) {
                return Bloodhound.tokenizers.whitespace(d.DisplayText);
            }
    

    and remember when you create the typeahead set the displayKey to the name of the property in your collection that has the text data you want to display. For me this was always the same as the property I wanted to tokenize - so my typeahead statement looked like the following:

    $('#my-typeahead').typeahead({
            hint: true,
            highlight: true,
            minLength: 3
            },
        {
            name: 'someName',
            displayKey: 'DisplayText',
            source: myBloodhound.ttAdapter()
        }
    
    0 讨论(0)
  • 2021-02-01 01:52

    The accepted answer, although correct at its time, is not of much use given that typeahead 0.10 is long outdated. Current version is 1.2.1 (as of 2018)

    So answering the original question,
    Here's a reference tutorial that has step by step explanation of using Typeahead with Bloodhound (local, prefetch, remote and a combination of these) with JS fiddles based on the still maintained fork - Typeahead v1.2.1

    0 讨论(0)
  • 2021-02-01 01:53

    change to:

    source : products.ttAdapter()

    0 讨论(0)
提交回复
热议问题