代码之家  ›  专栏  ›  技术社区  ›  Anenth

无法读取未定义的属性“isArray”

  •  1
  • Anenth  · 技术社区  · 12 年前

    我正在使用主干网、requirejs和yeoman构建一个应用程序。

    我正在使用twitter的typeaheadjs并收到此错误 随机 ! 大多数时候它是有效的,但有时提前打字甚至不会出现任何错误!之后打字就不起作用了 建筑 (咕哝)这是我称之为打字的那一页

    define([
        'jquery',
        'underscore',
        'backbone',
        'templates',
        ...
        'typeahead',
        ...
        ], function ( $, _, Backbone, JST, a, b, typeahead, c, d) {
    

    这是我初始化视图的render()内部的Typeahead的位置

    this.collection.fetch({
        success: function (data) {
            $('#SerachProduct').typeahead({
                name: 'abc',
                valueKey: 'name',
                local: data.toJSON(),
                template: JST['app/scripts/templates/typeahead.ejs']
            });
        },
        error: fun() {..
        }
    }
    

    这是github回购 Github

    1 回复  |  直到 12 年前
        1
  •  2
  •   kryger    12 年前

    Typeahead不兼容AMD,您需要定义 shim 配置。它将类似于:

    requirejs.config({
      // ...
      shim: {
        "typeahead": {
          deps: ['jquery'],
          exports: 'jQuery.fn.typeahead'
        }
      }
    });
    
    define(['jquery', 'typeahead'], function ($, youCanIgnoreThis) {
      var opts = {
        // ...
      };
      $("#SearchProduct").typeahead(opts);
    })
    

    阅读 the documentation 了解更多详细信息。