Javascript typeahead jquery-获取索引值
我正在使用twitter typeahead插件,我正在尝试获取值及其索引,但它不起作用Javascript typeahead jquery-获取索引值,javascript,php,jquery,Javascript,Php,Jquery,我正在使用twitter typeahead插件,我正在尝试获取值及其索引,但它不起作用 <script> var substringMatcher = function(strs) { return function findMatches(q, cb) { var matches, substringRegex; // an array that will be populated with substring matches matches =
<script>
var substringMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
matches.push(str);
}
});
cb(matches);
};
};
states = [];
states[180693]="MARIA DE JESUS LUZIA PAULINO";
states[339429]="MARCOS BRINNER LUZIA PAULINO";
states[366956]="RENATO ANDRADE";
$('#bloodhound .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: substringMatcher(states)
}).on('typeahead:selected', function (obj, datum) {
$("#era").val(datum);
console.log(obj);
});;
</script>
var substringMatcher=函数(strs){
返回函数findMatches(q,cb){
var匹配,substringRegex;
//将填充子字符串匹配项的数组
匹配项=[];
//用于确定字符串是否包含子字符串'q'的正则表达式`
substregex=新的RegExp(q,‘i’);
//在字符串池中迭代并查找
//包含子字符串'q',将其添加到'matches'数组中
$。每个(str,功能(i,str){
if(子相关性测试(str)){
匹配。推(str);
}
});
cb(比赛);
};
};
国家=[];
国家[180693]=“玛丽亚·德·耶稣·卢西亚·保利诺”;
国家[339429]=“MARCOS BRINNER LUZIA PAULINO”;
国家[366956]=“雷纳托·安德拉德”;
$(“#猎犬.提前键入”).提前键入({
提示:没错,
推荐理由:没错,
最小长度:1
},
{
名称:“州”,
来源:子字符串匹配器(状态)
}).on('typeahead:selected',功能(obj,基准){
美元(“#纪元”).val(基准);
控制台日志(obj);
});;
在这种情况下,声明[366956]=“RENATO ANDRADE”代码>我也想得到索引值366956,但我没有找到实现它的方法