我正在使用Twitter bootstrap,我使用它的typeahead 我用了这段代码:
$('#demo1').typeahead({
source:[
{ id: 1, name: 'Toronto' ,country: 'usa'},
{ id: 2, name: 'Montreal',country: 'china' },
{ id: 3, name: 'New York',country: 'usa' },
{ id: 4, name: 'Buffalo' ,country: 'china'},
{ id: 5, name: 'Boston' ,country: 'usa'},
{ id: 6, name: 'Columbus',country: 'china' },
{ id: 7, name: 'Dallas' ,country: 'italy'},
{ id: 8, name: 'Vancouver' ,country: 'turky'},
{ id: 9, name: 'Seattle' ,country: 'france'},
{ id: 10, name: 'Los Angeles' ,country: 'usa'}
],
itemSelected: displayRes
});
这是displayRes
函数
function displayRes(item, val,text) {
console.log(val);
console.log(text);
$('#demo1').val('');
}
当我进入控制台时 val :是所选项目的ID& 文字:是所选项目的名称
但如何在displayRes
函数中获得国家/地区?