【问题标题】:MVC Can't use certain JS LibrariesMVC 不能使用某些 JS 库
【发布时间】:2015-08-01 07:57:37
【问题描述】:

我在我的项目中添加了一个新的 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库吗?错误明确提示没有。
  • @Satpal 还不够吗?我会以什么其他方式加载库?

标签: javascript jquery asp.net-mvc twitter-bootstrap bootstrap-typeahead


【解决方案1】:

尝试安装typeahead nuget package,在包含jquery之后添加脚本&lt;script src="~/Scripts/bootstrap3-typeahead.js"&gt;&lt;/script&gt;的链接,然后它就可以工作了

【讨论】:

  • 不幸的是,这没有帮助,当我查看源代码时,它删除了“~”,但我仍然收到错误。
  • @KenLund,我刚刚在我的解决方案中添加了 typehead nuget 包,插入了指向 js 的链接,粘贴了您的代码,它就可以工作了! :) 但我使用 bootstrap3-typeahead.js
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多