Twitter引导程序在typeahead上预先输入多个ID值:已选中?

时间:2018-04-17 22:14:10

标签: javascript typeahead.js

我在我的网站上使用Twitter bootstrap typeahead。

在输入“A”的自动提示中点击一行时,输入“A”自动提示和隐藏输入“B”以获取ID

问题是我在json上有相同的数据:

id:1 名字:塞巴斯蒂安 姓氏:renard

id:8 名字:塞巴斯蒂安 姓氏:renard

当我选择这2个建议中的一个(在输入“A”上)时,隐藏输入“B”上的值为:1,8

我只想在输入“B”上输入所选建议的ID,如“1”而不是“1,8”。

这是我的javascript代码:

$(document).ready(function() {
// globalSearch
var resultList, d;
$('input.form-control').typeahead({    
    name: 'typeahead',
	valueKey: 'id' ,
    remote: {
      url: 'sql/sql_globalSearch.php?query=%QUERY',
      filter: function(data) {
        d = data;
        resultListFull = data.map(function(item) {
          return item.prenom+' '+item.nom+', '+item.age+' ans, '+item.ville+' ('+item.dpt+')';
        });
        resultList = data.map(function(item) {
          return item.prenom+' '+item.nom;
        });
        resultID = data.map(function(item) {
          return item.id;
        });
        return resultListFull;
      }
    }   
}).on('typeahead:selected typeahead:autocompleted', function(ev, suggestion) {
	//$('input.form-control').val(resultList);
	$('input.globalSearchID').val(resultID);
});
//End globalSearch	
<input type="text" class="form-control" placeholder="Rechercher une personne...." name="globalSearch" id="globalSearch"><input type="hidden" class="globalSearchID" name="globalSearchID" id="globalSearchID">

你能帮我解决这个问题吗?

亲切的问候,

的Sebastien

0 个答案:

没有答案