【发布时间】: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