无法使 JQuery Typeahead/Autocomplete 工作(ASP.NET 核心)

Can't get JQuery Typeahead/Autocomplete to work (ASP.NET Core)

我正在使用 JQuery Typeahead 功能的最基本实现,但我无法让它在我的 ASP.NET 核心应用程序上运行。代码检查没有发现任何错误,一切看起来都应该有效。非常感谢各位编码老手的帮助!

这是我的 _Layout.cshtml 文件:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - Test</title>

    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
    <div class="container">
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>

    <script src="~/lib/jquery/jquery.js"></script>
    <script src="~/lib/typeahead.js/typeahead.jquery.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

    <script src="~/js/site.js" asp-append-version="true"></script>
    @RenderSection("Scripts", required: false)
</body>
</html>

这是 Index.cshtml

 @{
    ViewData["Title"] = "Home Page";
}
    <br />
    <input id="type-ahead" type="text" class="form-control" />

     @section Scripts {
            <script type="text/javascript">
                $("#type-ahead").typeahead({
                    source: { data: ["This", "That", "Whatever"]}
                });</script>
        }

当我键入任何内容时,自动完成功能永远不会启动。同样,控制台中没有错误。

非常感谢。

--- 值

我终于让它工作了。我用 jquery-typeahead@2.11.0

替换了 typeahead.js@0.11.1 库

然后我用以下内容包围了我的输入:

<div class="typeahead__container">
    <input id="type-ahead" type="text" class="form-control"/>
</div>