【问题标题】:Typeahead.js - Cannot read property of 'isArray' of undefinedTypeahead.js - 无法读取未定义的“isArray”属性
【发布时间】:2013-04-19 15:29:57
【问题描述】:

我正在尝试在 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> 

【问题讨论】:

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


    【解决方案1】:

    倒置 typehead 和 jquery 脚本定义,因为显然第一个取决于第二个:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2020-10-30
      • 2019-10-09
      • 1970-01-01
      相关资源
      最近更新 更多