我正在使用bootstrp“typehead”自动完成小部件,我有以下场景:
suggestion: Handlebars.comp( tr's.. )
- >将出现在$('#suggestions')选择器
$('#typeahead-1').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
name: 'PriceItems',
displayKey: 'Name',
limit: 10,
minLenght: 1,
templates: {
empty: [
'<div>',
'unable to find any items',
'</div>'
],
suggestion: Handlebars.compile("<tr><td>{{Name}}</td><td><span class='popupItem'>CS</span></td><td><span class='popupItem'>S</span></td><td><span class='popupItem'>M</span></td><td><span class='popupItem'>L</span></td><td><span class='popupItem'>XL</span></td></tr>")
},
source: function (query, process) {
jQuery.ajax({
type: "POST",
url: "/Mapping/FetchData",
dataType: "json",
contentType: "application/json; charset=utf-8",
async: true,
success: function (data) {
process(data);
},
failure: function (errMsg) {
alert(errMsg);
}
});
}
});
<input type="text" class="form-control" placeholder="Type item name..." id="typeahead-1">
<div>
<table class='table table-striped dt-responsive dataTable'>
<tbody id="suggestions"></tbody>
</table>
</div>