Programmatically triggering typeahead.js result display

后端 未结 17 1838
余生分开走
余生分开走 2020-11-30 05:01

I am using Twitter\'s typeahead.js (https://github.com/twitter/typeahead.js/) on an input field which is pre filled from a query string. After loading the page, i\'d like to

17条回答
  •  失恋的感觉
    2020-11-30 05:10

    This worked for me.

    $( document ).ready(function() {
        $('#the-basics .typeahead').typeahead({
          hint: false,
          highlight: true,
          minLength: 0
        },
        {
          name: 'states',
          displayKey: 'value',
          source: substringMatcher(states)
        });
    
        //set a value to input to trigger opening
        $(".typeahead").eq(0).val("a").trigger("input");
        //remove value for end user
        $(".typeahead").eq(0).val("");
    
    });
    

    See here for example: http://joshuamaynard.com/sandbox/autocomplete

提交回复
热议问题