2016-08-10 2 views
0

Ich möchte TypeAhead-Bibliothek in einem TypeScript-Modul aufrufen. Wie erreiche ich ein ähnliches Skript wie das folgende?Call TypeAhead-Methoden aus TypeScript

/// <reference path="typings/jquery/jquery.d.ts" /> 
/// <reference path="typings/typeahead/typeahead.d.ts" /> 

$ReferrerSearchInput.typeahead({ 
    hint: false, 
    highlight: false, 
    minLength: 3 
}, 
{ 
    name: "Referrers", 
    display: "DisplayValue", 
    source: referrersDatasource, 
    limit: 20, 
    templates: { 
     suggestion: function(data) { 
      return data.FullName; 
     } 
    } 
}); 

Antwort

1

Dies ist, wie ich es gelöst:

const datasource = new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.whitespace, 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
    remote: { 
     url: "MyUrl%QUERY", 
     wildcard: "%QUERY" 
    } 
}); 

const inputOptions = { 
    hint: true, 
    highlight: true, 
    minLength: 0 
}; 

const apiSettings = { 
    name: "DisplayName", 
    display: "Name", 
    source: datasource, 
    limit: 20, 
    templates: { 
     empty: "", 
     suggestion(data: any) { 
      return ""; 
     } 
    } 
}; 

$ReferrerSearchInput.typeahead(inputOptions, apiSettings);