无法使用Typeahead

时间:2015-09-21 05:15:13

标签: typeahead.js

我正在使用Twitter的“typeahead.js 0.11.1”,但我收到此错误“无法读取未定义的属性'标记符'”。把我的代码放在下面,请帮我检查一下我做错了什么。

paths: {
    'jquery'                : 'assets/lib/jquery.min',
    'underscore'            : 'assets/lib/underscore-min',         
    'backbone'              : 'assets/lib/backbone.min',
    'marionette'            : 'assets/lib/backbone.marionette.min',
    'bootstrap'             : 'assets/lib/bootstrap.min',
    'typeahead'             : 'assets/lib/typeahead.bundle.min',       
},

shim: {
    typeahead:{
        deps: ['jquery'],
        exports:'Bloodhound',
        init: function ($) {
            return require.s.contexts._.registry['typeahead.js'].factory( $                          );
        }
    }

}

Marionette的观看代码如下:

    define(['jquery',   'marionette','templates', 'underscore','typeahead'], 
    function $,Marionette, templates, _,Bloodhound) {
              'use strict';
          ..................
        onShow:function(){
           var tours = new Bloodhound({
              datumTokenizer: function (datum) {
                  return Bloodhound.tokenizers.whitespace(datum.value);
              },
              queryTokenizer: Bloodhound.tokenizers.whitespace,
              remote: {
                  url: '/api/infos?t=ALL',
              }
          });

          // Initialize the Bloodhound suggestion engine
          tours.initialize();
          // Instantiate the Typeahead UI
          $('.typeahead').typeahead(null, {
              displayKey: 'value',
              source: tours.ttAdapter()
          });

    },

1 个答案:

答案 0 :(得分:0)

我在Backbone / Marionette和RequireJS配置方面遇到了类似的问题。要做到正确的重点是使用单独的文件要求typeahead.jquery.js和bloodhound.js。我使用的是typeahead.bundle.js,但它不起作用。在经历了几个小时的挫折之后发布了这个。

相关问题