有人能看出我在这里做错了什么吗?我花了很长时间查看各种自动完成代码。从Json调用返回的值我可以选择,但我需要设置Id隐藏字段。我已经在更新器函数中尝试了各种方法(日志、警报等),但都没有反应。我相信它没有触发。
var teamNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('Text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'List'
});
teamNames.initialize();
$('#remote #FullName').typeahead(null, {
name: 'team-names',
displayKey: 'Text',
source: teamNames.ttAdapter(),
updater: function(item){$('#Id').val(map[item].Value)}
})
非常感谢您的任何观察和建议。如果您认为您有答案,请将其设置为答案,这样我就可以确认并回复了。更新-我怀疑我使用了一些过时或不兼容的代码。我现在已经使用了。
$('#FullName').bind('typeahead:selected', function (obj, datum, name) {}
我在这里找到的GitHub上的问题,感谢andy3rdworld,它完美地发挥了作用