我正在使用typeahead填充搜索建议。我可以看到在控制台的建议,但无法填充它与html模板。请在下面找到我使用的源代码。
$.typeahead({
input: '.js-typeahead',
minLength: 0,
order: "asc",
hint: true,
searchOnFocus: true,
dynamic: true,
delay: 500,
source: {
ajax:{
type: "POST",
url: "/my-url/",
data: {
q1: 'blah',
q2: "{{query}}"
},
success: function (data) {
$.map(data['data'], function(venue, index) {
// console.log(venue["name"])
// console.log(venue)
return venue;
});
}
},
error: function(err){
console.log('ERROR : ', err);
}
},
display: ["name"],
template: '<div>' +
' <span class="lname">{{name}}</span>' +
"</div>",
debug: true
});
字符串
然而,它在控制台中工作正常,但无法使用HTML渲染它。
- 感谢您的帮助!***
1条答案
按热度按时间fzwojiic1#
您在模板中遗漏了“% s”,并且没有提供哪个模板。下面是一个示例,其中底层数据是ID为
.id
的JSON和要显示.name
的文本:字符串