Javascript 在typeahead中,当我选择空模板时触发了哪个事件?

Javascript 在typeahead中,当我选择空模板时触发了哪个事件?,javascript,jquery,twitter-bootstrap,typeahead.js,bootstrap-typeahead,Javascript,Jquery,Twitter Bootstrap,Typeahead.js,Bootstrap Typeahead,当我在twitter引导程序typeahead中选择空模板时,我想调用一个函数。有什么活动可以这样做吗 在下面的代码中,on('typeahead:selected',fn)当我单击返回的值之一时,会触发事件。在这个事件触发之后,我继续键入一些不会返回值的世界。在这种情况下,我希望在单击“无建议”部分时清空全局对象(即myObject=null) 以下是代码: $('#myinput').typeahead({ minLength: 1,

当我在twitter引导程序typeahead中选择空模板时,我想调用一个函数。有什么活动可以这样做吗

在下面的代码中,
on('typeahead:selected',fn)
当我单击返回的值之一时,会触发事件。在这个事件触发之后,我继续键入一些不会返回值的世界。在这种情况下,我希望在单击“无建议”部分时清空全局对象(即
myObject=null

以下是代码:

$('#myinput').typeahead({
                minLength: 1,
                highlight: true,
            },
            {
                name: 'myinput',
                displayKey: 'displayName',
                templates: {
                    empty: [
                    '<div>',
                    'No suggestion',
                    '</div>'
                    ].join('\n'),
                    suggestion: function (val) {
                        return '<div>' + val.value + '</div>'
                    }
                },
                source: function (query, cb) {
                    $.ajax({
                            url: "...",
                            data: "...",
                            success: function(result){
                                cb(result);
                            }
                    });
                }
            }).on('typeahead:selected', function (event, data) {
                    myObject = data;
            });
$('#myinput')。键入前置({
最小长度:1,
推荐理由:没错,
},
{
名称:“myinput”,
displayKey:'displayName',
模板:{
空的:[
'',
“没有建议”,
''
].join('\n'),
建议:功能(val){
返回“”+val.value+“”
}
},
来源:函数(查询,cb){
$.ajax({
网址:“…”,
数据:“…”,
成功:功能(结果){
cb(结果);
}
});
}
}).on('typeahead:selected',函数(事件、数据){
myObject=数据;
});