Typeahead.js - 无法读取未定义的 'isArray' 属性

3

我正在尝试在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> 
1个回答

5

typeheadjquery脚本定义反转,因为显然第一个依赖于第二个:

<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>
<script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" type="text/javascript"></script>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接