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()
});
},
嗨!你解決了這個問題嗎?我有完全相同的問題 – SimonQuest
是的,請看這裏http://www.bluepage.me/case/4/ – Sunorth