我正在使用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 = [];
// 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>
在这种情况下states[366956]="RENATO ANDRADE";
我也希望得到索引值366956,但我找不到实现它的方法