typeahead.js onselect项重定向到新窗口 [英] typeahead.js onselect item redirect to new window
问题描述
我正在使用带有json响应的远程URL(New typeahead.js)
I am use remote url with json response ( New typeahead.js)
我的javascript:
$(document).ready(function() {
$('input.country').typeahead({
valueKey: 'name',
remote : {
url : 'example.in/d.php?query=%QUERY',
filter: function (parsedResponse) {
var dataset = [];
for (i = 0; i < parsedResponse.length; i++) {
dataset.push({
name: parsedResponse[i].name
});
}
if (parsedResponse.length == 0) {
dataset.push({
name: "No results"
}); }
return dataset;
},
},
});;
})
我的json响应:
[{"name":诺基亚110",url:"example.com/nokia-110"},{"name":诺基亚210",url:"example.com/nokia-210"}]
[{"name":"Nokia 110",url:"example.com/nokia-110"},{"name":"Nokia 210",url:"example.com/nokia-210"}]
那么如何在所选名称上提供URL链接?
so how to give URL link on selected name ?
推荐答案
您需要更新Typeahead.js使用的模板,并在其中显示URL.
You need to update the template that Typeahead.js uses and in it you would display the URL.
请参阅: https://github.com/twitter/typeahead.js/#datum
对于一个很好的与Typeahead.js兼容的模板系统,我建议您查看 http://twitter.github.io/hogan.js/
For a good templating system that works well with Typeahead.js I would recommend you look at http://twitter.github.io/hogan.js/
这篇关于typeahead.js onselect项重定向到新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!