我正在使用Twitter的Typeahed.js库从单个输入框中搜索数据库中的多个数据集。
我目前正在使用6个数据集(请参阅下面的代码),我想再添加1个。我发现它不适用于第7个数据集(products dataset
来自下面的代码)。在输入框中键入搜索查询时,它只会为前六个数据集发送GET AJAX请求,而忽略第7个数据集?
GET http://127.0.0.1/app/typeahead_orders.json?q=MSI-20mA
GET http://127.0.0.1/app/typeahead_invoices.json?q=MSI-20mA
GET http://127.0.0.1/app/typeahead_services.json?q=MSI-20mA%
GET http://127.0.0.1/app/typeahead_serials.json?q=MSI-20mA%
GET http://127.0.0.1/app/typeahead_users.json?q=MSI-20mA%
GET http://127.0.0.1/app/typeahead_licenses.json?q=MSI-20mA%
库文档正在倾倒,我还没有看到它提到你可以使用的数据集数量的任何限制......
$('#search-query').typeahead([
{
name: 'orders',
remote: base_url+"utilities/ajaxprocess/typeahead_orders.json?q=%QUERY",
template: '<a href="'+base_url+'orders/view/{{order_id}}">{{value}} - Reference no.: {{reference_number}}</a>',
header: '<h5 class="search-result-header"><i class="icon-shopping-cart"></i> Orders</h5>',
engine: Hogan,
limit: 6
},
{
name: 'invoices',
remote: base_url+"utilities/ajaxprocess/typeahead_invoices.json?q=%QUERY",
template: '<a href="'+base_url+'invoices/view/{{invoice_id}}">{{invoice_number}} - {{company}}</a>',
header: '<h5 class="search-result-header"><i class="icon-file"></i> Invoices</h5>',
engine: Hogan,
limit: 6
},
{
name: 'services',
remote: base_url+"utilities/ajaxprocess/typeahead_services.json?q=%QUERY%",
template: '<a href="'+base_url+'services/view/{{rma_id}}">{{value}} - {{firstname}} {{lastname}}</a>',
header: '<h5 class="search-result-header"><i class="icon-wrench"></i> RMA services</h5>',
engine: Hogan,
limit: 6
},
{
name: 'serials',
remote: base_url+"utilities/ajaxprocess/typeahead_serials.json?q=%QUERY%",
template: '<a href="'+base_url+'serials/view/{{serial_id}}">{{value}} - {{product}} {{module_name}}</a>',
header: '<h5 class="search-result-header"><i class="icon-barcode"></i> Serials</h5>',
engine: Hogan,
limit: 6
},
{
name: 'users',
remote: base_url+"utilities/ajaxprocess/typeahead_users.json?q=%QUERY%",
template: '<a href="'+base_url+'users?f=1&filter_id={{user_id}}">{{firstname}} {{lastname}} - {{email}}</a>',
header: '<h5 class="search-result-header"><i class="icon-user"></i> Users</h5>',
engine: Hogan,
limit: 6
},
{
name: 'licenses',
remote: base_url+"utilities/ajaxprocess/typeahead_licenses.json?q=%QUERY%",
template: '<a href="'+base_url+'licenses?f=1&filter_id={{license_id}}">{{key}} - {{version}}</a>',
header: '<h5 class="search-result-header"><i class="icon-lock"></i> Licenses</h5>',
engine: Hogan,
limit: 6
},
{
name: 'products',
remote: base_url+"utilities/ajaxprocess/typeahead_products.json?q=%QUERY%",
template: '<a href="'+base_url+'products?f=1&filter_id={{product_id}}">{{code}} - {{name}}</a>',
header: '<h5 class="search-result-header"><i class="icon-briefcase"></i> Products</h5>',
engine: Hogan,
limit: 6
}
]).on('typeahead:selected', function($e, data) {
window.location = data.url;
});
答案 0 :(得分:2)
好的我明白了。它没有限制,但默认的最大并行请求是6.来自typeahead.js docs:
maxParallelRequests – The max number of parallel requests typeahead.js can have pending. Defaults to 6.
所以我增加了这个并且它有效。这是最终更正的代码:
$('#search-query').typeahead([
{
name: 'orders',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_orders.json?q=%QUERY",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'orders/view/{{order_id}}">{{value}} - Reference no.: {{reference_number}}</a>',
header: '<h5 class="search-result-header"><i class="icon-shopping-cart"></i> Orders</h5>',
engine: Hogan,
limit: 6
},
{
name: 'invoices',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_invoices.json?q=%QUERY",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'invoices/view/{{invoice_id}}">{{invoice_number}} - {{company}}</a>',
header: '<h5 class="search-result-header"><i class="icon-file"></i> Invoices</h5>',
engine: Hogan,
limit: 6
},
{
name: 'services',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_services.json?q=%QUERY%",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'services/view/{{rma_id}}">{{value}} - {{firstname}} {{lastname}}</a>',
header: '<h5 class="search-result-header"><i class="icon-wrench"></i> RMA services</h5>',
engine: Hogan,
limit: 6
},
{
name: 'serials',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_serials.json?q=%QUERY%",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'serials/view/{{serial_id}}">{{value}} - {{product}} {{module_name}}</a>',
header: '<h5 class="search-result-header"><i class="icon-barcode"></i> Serials</h5>',
engine: Hogan,
limit: 6
},
{
name: 'users',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_users.json?q=%QUERY%",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'users?f=1&filter_id={{user_id}}">{{firstname}} {{lastname}} - {{email}}</a>',
header: '<h5 class="search-result-header"><i class="icon-user"></i> Users</h5>',
engine: Hogan,
limit: 6
},
{
name: 'licenses',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_licenses.json?q=%QUERY%",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'licenses?f=1&filter_id={{license_id}}">{{key}} - {{version}}</a>',
header: '<h5 class="search-result-header"><i class="icon-lock"></i> Licenses</h5>',
engine: Hogan,
limit: 6
},
{
name: 'products',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_products.json?q=%QUERY%",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'products?f=1&filter_id={{product_id}}">{{code}} - {{name}}</a>',
header: '<h5 class="search-result-header"><i class="icon-briefcase"></i> Products</h5>',
engine: Hogan,
limit: 6
},
{
name: 'tasks',
remote: {
url: base_url+"utilities/ajaxprocess/typeahead_tasks.json?q=%QUERY%",
maxParallelRequests: 8,
},
template: '<a href="'+base_url+'tasks?f=1&filter_id={{task_id}}">#{{task_id}} - {{description}}</a>',
header: '<h5 class="search-result-header"><i class="icon-briefcase"></i> Tasks</h5>',
engine: Hogan,
limit: 6
}
]).on('typeahead:selected', function($e, data) {
window.location = data.url;
});
答案 1 :(得分:0)
我没有听说过这样的限制,我想知道前6个可能满足的最大返回结果数量是多少?
快速测试将基本上强制几个远程查询始终不返回任何内容。
如果您的第七次搜索开始受到打击,那么可以解释它。
答案 2 :(得分:0)
如果有人遇到这个旧问题,并希望将maxPendingRequests设置增加到6以上(或使其更小),请参阅this PR我最近提交给维护的typeahead分支。
答案 3 :(得分:0)
打开Twitter typeahead.js文件。
搜索:“maxPendingRequests = 6”
而不是6只要放置你想要的任何值。
现在我可以看到超过6个请求并行运行。
它适用于我。
不要选择“maxParallelRequests”属性,它根本不起作用......
我确信它是最终解决方案.....