获取一些参数到typeahead bootstrap中的选定项目

时间:2014-10-17 19:34:36

标签: javascript twitter-bootstrap-3

我正在使用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函数中获得国家/地区

0 个答案:

没有答案