javascript - Twitter Typeahead.js, "one of local, prefetch, or remote is required",即使提供

标签 javascript typeahead typeahead.js twitter-typeahead

我有两个预输入输入框。这是两个输入框的代码。

$('#input1').typeahead({
    name: 'DrugName',
    remote: {
        url: 'Model/Dataset1.js',
        filter: function (parsedResponse) {
            // do whatever processing you need here
            return parsedResponse;
        }
    },
    valueKey: "DrugName",
    template: [
        '<div class="typeahead-dropdown">',
        '<p class="tt-drugname">{{DrugName}}</p>',
        '</div>',
    ].join(''),
    engine: Hogan
});

第二个:

$('#input2').typeahead({
    name: 'Name',
    remote: {
        url: 'Model/Dataset2.js',
        filter: function (parsedResponse) {
            // do whatever processing you need here
            return parsedResponse;
        }
    },
    valueKey: "Name",
    template: [
        '<div class="typeahead-dropdown">',
        '<p class="tt-drugname">{{DrugName}}</p>',
        '</div>',
    ].join(''),
    engine: Hogan
});

第一个工作正常,但当我选择下拉选项时,第二个返回此错误。

Error: one of local, prefetch, or remote is required

我尝试了远程操作,但仍然收到错误。我相信代码中没有任何问题。谁能帮我写一下代码吗?


回答此问题

如果您收到错误 Error: one of local, prefetch, or remote is required 即使您提供了本地、预取或远程源。问题不在于 JavaScript 代码。

我通过编辑输入 DOM 元素修复了这个问题。

这是<input type="text" class="tw-typeahead" autofocus="autofocus" />前。我把它改为<input type="text" class="tw-typeahead" /> ..

删除自动对焦属性修复了所有错误..很奇怪,但这就是问题所在。我与代码斗争了大约两天,但终于找到了!..

谢谢

拉胡尔·帕蒂尔

最佳答案

如果您收到错误 Error: one of local, prefetch, or remote is required 即使您提供了本地、预取或远程源。问题不在于 JavaScript 代码。

我通过编辑输入 DOM 元素修复了这个问题。

这是<input type="text" class="tw-typeahead" autofocus="autofocus" />前。我把它改为<input type="text" class="tw-typeahead" /> ..

删除自动对焦属性修复了所有错误..很奇怪,但这就是问题所在。我与代码斗争了大约两天,但终于找到了!..

谢谢

拉胡尔·帕蒂尔

关于javascript - Twitter Typeahead.js, "one of local, prefetch, or remote is required",即使提供,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21403653/

相关文章:

Javascript:将值放入两个单独的表单字段中

javascript - html 源代码中看不到脚本标签

javascript - 使用extjs有什么优点和缺点?

javascript - 神秘的 JavaScript/jQuery 代码

javascript - 如何在运行时确定可注入(inject)的 Angular 服务?

ajax - 带有 JSON REST 的 Twitter Bootstrap Typeahead

javascript - AngularUI-Bootstrap Typeahead : Grouping results

mysql - Yii2 Kartik-V Typeahead 高级小部件 : How to store result in Mysql

javascript - 当我在 typeahead 中选择一个元素时,如何创建一个 div?

javascript - 无法在我的 fiddle 中进行提前输入