我使用 angular-typehead#1.0.2 与 typehead#0.11.1 和 bloodhound#0.11.1
我正在使用带有远程数据源的Typeahead的多个数据集。
当我在输入文本框中输入单词时,有时总计远程呼叫正在进行,但有时无法正常呼叫。
任何遇到此问题的人都请帮忙。
见下面的示例。
var request1 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request1&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
var request2 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request2&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
var request3 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request3&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
var request4 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request4&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
var request5 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request5&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
var request6 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request6&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
var request7 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request7&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
var request8 = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/request.php?search_type=request8&search_text=%QUERY',
prepare: function(query, settings) {
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
filter: function(data) {
if (data.data) {
return $.map(data.data.search_result, function(match) {
return {
match: match.text
};
});
}
}
}
});
Datasets = [{
name: 'request1',
display: 'name',
templates: {
header: 'Search Header 1',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request1.ttAdapter(),
limit: 5
},
{
name: 'request2',
display: 'name',
templates: {
header: 'Search Header 2',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request2.ttAdapter(),
limit: 5
},
{
name: 'request3',
display: 'name',
templates: {
header: 'Search Header 3',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request3.ttAdapter(),
limit: 5
},
{
name: 'request4',
display: 'name',
templates: {
header: 'Search Header 4',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request4.ttAdapter(),
limit: 5
},
{
name: 'request5',
display: 'name',
templates: {
header: 'Search Header 5',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request5.ttAdapter(),
limit: 5
},
{
name: 'request6',
display: 'name',
templates: {
header: 'Search Header 6',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request6.ttAdapter(),
limit: 5
},
{
name: 'request7',
display: 'name',
templates: {
header: 'Search Header 7',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request7.ttAdapter(),
limit: 5
},
{
name: 'request8',
display: 'name',
templates: {
header: 'Search Header 8',
suggestion: function(e) {
return ('<div class="select-drop-down-item"><a href="#' + e.slug + '">' + e.name + '</a></div>');
},
footer: '<div class="dataset-footer"></div>',
empty: ''
},
source: request8.ttAdapter(),
limit: 5
},
];
&#13;