为什么预输入不显示结果?

Why typeahead does not show results?

提问人:Megan Clerc 提问时间:3/7/2023 最后编辑:Megan Clerc 更新时间:3/7/2023 访问量:29

问:

我使用这个插件

HTML 元素为:

<input class="form-control typeahead" maxlength="50" id="secondname" required="required" name="secondname" type="text">

    $("#secondname").typeahead({
        minLength: 3,
        async: true,
        source: function (query, process) {
            return fetchPatientForm({ secondname: query })
                .then((res) => res.data)
                .then((data) => {
                    console.log(data);
                    return process(data);
                });
        },
    });

响应

 console.log(data);

是:

[{id: 39, name: 'Михаил', secondname: 'Попов', patronymic: '3' }];

所以也没有错误和结果。我做错了什么?

我试图从服务器返回普通数组,例如 [1, 2, 3] 它也不起作用

jquery typeahead.js typeahead

评论

1赞 Dave Newton 3/7/2023
好奇为什么你不关注他们的异步文档来获取异步源函数:github.com/twitter/typeahead.js/blob/master/doc/......
0赞 Megan Clerc 3/7/2023
您能举个例子吗?我使用源但异步

答: 暂无答案