我想在TypeScript模块中调用TypeAhead库。如何实现类似于后续脚本的脚本?
/// <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;
}
}
});
答案 0 :(得分:1)
这是我解决它的方式:
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);