我正在尝试在ASP MVC视图中实现typeahead.js
自动完成/搜索功能,但是在Chrome控制台上,当页面加载时,我收到以下错误:
Uncaught TypeError: Cannot read property 'isArray' of undefined ... typeahead.js:26
这是typeahead.js文件中所涉及的代码部分。
isString: function(obj) {
return typeof obj === "string";
},
isNumber: function(obj) {
return typeof obj === "number";
},
isArray: $.isArray, <-UncaughtTypeError: Cannor read property of 'isArray' of undefined
isFunction: $.isFunction,
isObject: $.isPlainObject,
isUndefined: function(obj) {
return typeof obj === "undefined";
},
这是我使用的
typeahead
代码以及声明。<script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.typeahead').typeahead({
source: function (term, process) {
var url = '@Url.Content("~/Home/GetNames")';
return $.getJSON(url, { term: term }, function (data) {
return process(data);
});
}
});
});
</script>
这里是使用输入元素进行搜索的示例
<form class="navbar-search pull-left">
<input type="text" value="" id="typeahead" data-provide="typeahead" class="search-query" /> @*placeholder=" Agent search" />*@
</form>