0
我有這段代碼來設置twitter typeahead,它根本不工作。我驗證了json是正確的格式,並有正確的值等任何幫助將不勝感激。目前,它只記錄'Initializing autocomplete'
行。過濾器中的日誌從不會被調用,這似乎是由於某種原因引擎未初始化。當我輸入時,我看到了我定義的空模板。我也確認了確保將coffeescript編譯成適當的格式。Twitter typeahead bloodhound not prefetching
initAutocomplete: ->
console.log 'Initializing autocomplete'
engine = new Bloodhound
datumTokenizer: (d) ->
Bloodhound.tokenizers.obj.whitespace(d.val)
queryTokenizer: Bloodhound.tokenizers.whitespace
limit: 10
prefetch:
url:'../api/v3/tickets/autocomplete'
filter: (list) ->
console.log 'List: '
console.log list
engine.initialize()
$('#tt-ticket.typeahead').typeahead null,
name: 'tickets'
displayKey: 'val'
source: engine.ttAdapter()
templates:
empty: [
'<div class="empty-message">',
'Unable to find any matches',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<p><strong>{{key}}</strong> – {{value}}</p>')
的JSON已經被證實具有這種格式:
[{"key":"Id","val":1}, {"key":"Some other key", "val" : "some val"}]