2015-09-21 72 views
2

我正在使用Twitter的「typeahead.js 0.11.1」,但我得到了這個錯誤「無法讀取屬性'tokenizers'未定義」。把我的代碼放在下面,請幫我檢查我做錯了什麼。使用Typeahead無法讀取未定義的屬性'tokenizers'

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($       ); 
     } 
    } 

} 

木偶的觀點如下代碼:

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() 
      }); 

    }, 
+0

嗨!你解決了這個問題嗎?我有完全相同的問題 – SimonQuest

+0

是的,請看這裏http://www.bluepage.me/case/4/ – Sunorth

回答

0

我曾與骨幹/木偶和RequireJS配置類似的問題。重要的一點是要使用單獨的文件來要求typeahead.jquery.js和bloodhound.js。我正在使用typeahead.bundle.js,它不會工作。在沒有幾個小時的挫折之後發帖。

相關問題