MVC 不能使用某些 JS 库

MVC Can't use certain JS Libraries

我在我的项目中添加了一个新的 js 库 (typeahead.bundle.js),但每当我尝试调用任何函数时,它都声称它们不存在。它似乎在 jQuery 而不是我的图书馆中查找:

Uncaught TypeError: $(...).typeahead is not a function
(anonymous function) @ Create:50
x.Callbacks.c @ jquery-1.10.2.min.js:21
x.Callbacks.p.fireWith @ jquery-1.10.2.min.js:21
x.extend.ready @ jquery-1.10.2.min.js:21q @ jquery-1.10.2.min.js:21

我在 jQuery-ui 中也发现了这个问题。

相关用法:

<script src="/Scripts/typeahead.bundle.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
    $( "#MemberSearch" ).typeahead({ //error line
            source: function (request, response) {
                $.ajax({
                    url: "/Operations/AutoCompleteMember",
                    type: "POST",
                    dataType: "json",
                    data: { term: request.term },
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item.Member, value: item.Member };
                        }))

                    }
                })
            },
            messages: {
                noResults: "", results: ""
            }
        });
    })
</script>

...

<div class="form-group">
            @Html.Label("Member Search", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBox("MemberSearch", "", htmlAttributes: new { @class = "form-control btn-group" })
                <button type="button" onclick="" class="btn btn-group" aria-label="Left Align">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                </button>
            </div>
        </div>

尝试安装 typeahead nuget package,在包含 jquery 之后将 link 添加到脚本 <script src="~/Scripts/bootstrap3-typeahead.js"></script> 然后就可以了