0
I have the following js code that prepares a search field using the Twitter Typeahead:
var users = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('cname'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'application/controller/TypeaheadSeed.php?QUERY=%QUERY'
});
users.initialize();
$('#input-friend-list-publication').typeahead({
hint: true,
highlight: true
}, {
name: 'users',
displayKey: 'cname',
source: users.ttAdapter(),
templates: {
header: '<div class="tt-header">Meus amigos</div>',
empty: [
'<div class="empty-message">',
' Não foi possível encontrar resultados para essa pesquisa.',
'</div>'
].join('\n'),
suggestion: Handlebars.compile(
'<div class="result-values" style="display: inline-block; vertical-align: top;" data-value="{{username}}">' +
' <img class="img-rounded" src="{{profilepicpath}}" alt="{{cname}}" title="{{cname}}" width="48" height="48" />' +
'</div>' +
'<div style="display: inline-block; vertical-align: top; margin-left: 10px">' +
' <div>{{cname}}</div>' +
'</div>')
}
});
How I get the value of the attribute data-value
? I even tried a solution using the function bind()
but unsuccessfully, see it below.
$('#input-friend-list-publication').bind('typeahead:selected', function () {
console.log($(this));
});
Note: my problem is not taking a value from an attribute data-
in itself.