2012-07-09 100 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