为什么typeahead建议未定义?

cor*_*ore 6 typeahead typeahead.js bloodhound

希望这不是重复:为什么bloodhound.get()返回undefined?

我升级到typeahead.js版本0.10.0.以前的版本正确地返回了建议.现在我收到undefined以下代码的回复:

// instantiate the bloodhound suggestion engine
var engine = new Bloodhound({
    datumTokenizer: function (d) { return [d]; },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    local: ["(A)labama", "Alaska", "Arizona", "Arkansas"]
});

// initialize the bloodhound suggestion engine
engine.initialize();

$('#typeahead').typeahead(null, {
        source: engine.ttAdapter()
    });
Run Code Online (Sandbox Code Playgroud)

这是我的小提琴:http://jsfiddle.net/ucUcn/6/

任何想法为什么会这样?

Cha*_*sch 9

local数组必须包含的对象,而不是字符串自理.

// instantiate the bloodhound suggestion engine
var engine = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.obj.whitespace('d'),
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  local: [{
    d: "(A)labama"
  }, {
    d: "Alaska"
  }, {
    d: "Arizona"
  }, {
    d: "Arkansas"
  }]
});

// initialize the bloodhound suggestion engine
engine.initialize();

$('#typeahead').typeahead(null, {
  displayKey: 'd',
  source: engine.ttAdapter()
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
<input id="typeahead" />
Run Code Online (Sandbox Code Playgroud)

摆弄以上修复:

的jsfiddle