2012-07-09 93 views
4

我有一個小問題得到這個工作。Bootstrap Typeahead只顯示第一個字母

服務器響應正確的json請求,但是typeahead只顯示我返回結果的第一個字母。例如,如果我K型它將顯示:
ķ
ķ
ķ
ķ

你能不能幫我找出爲什麼?

這裏是我的js

$('.user').typeahead({ 
source : function(typeahead, query) { 
    return $.post('getUser', { 
     query : query 
    }, function(data) { 
     return typeahead.process(data); 
    }); 
} 
}); 

和我的HTML

<input autocomplete="off" type="text" size="16" id="appendedInputButton" class="user" data-provide="typeahead"> 

我用下面的代碼

https://gist.github.com/1866577

謝謝。

+0

可能重複:http://stackoverflow.com/q/11346251/484072 – peacemaker 2012-07-09 19:48:18

回答

4

如果服務器與對象的數組具有屬性「接觸」響應,嘗試:

$('.user').typeahead({ 
    source : function(typeahead, query) { 
     return $.post('getUser', { 
      query : query 
     }, function(data) { 
      return typeahead.process(JSON.parse(data)); 
     }); 
    }, 
    property : 'contact' 
}); 
+0

我碰到下面的錯誤現在回到〜item.toLowerCase()的indexOf(this.query.toLowerCase()) – BaconJuice 2012-07-09 19:51:24

+0

什麼是從一個樣本響應。的getUser? – 2012-07-10 04:38:44

+0

以下內容以getUser [{「id」:「1」,「contact」:「[email protected]」},{「id」:「2」,「contact」:「[email protected]」 },{「id」:「3」,「co ntact」:「[email protected]」}] – BaconJuice 2012-07-10 12:17:39

-2

卸下類=「用戶」。它將開始顯示整個事情。

0

一直有今天自己這個同樣的問題,發現我需要確定並做

data-source="['THING1','THINGS2']" 

第一雙引號,那裏面單引號。我最初扭轉了局面,只得到1封信。另外,請確保數組末尾沒有尾隨,,因爲這也會導致只顯示一個字母。

+0

有趣的解決方案。我會檢查出來的!感謝分享。 – BaconJuice 2013-02-10 15:06:14