项目是用 Marionette+RequireJS. 最近要使用TypeaheadJS(0.11.1) 但是始终无法加载Bloodhound。麻烦各位帮忙看看错在哪里?错误信息:“Cannot read property 'tokenizers' of undefined”
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 view code:
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()
});
},