typeahead.js onselect项重定向到新窗口 [英] typeahead.js onselect item redirect to new window

查看:114
本文介绍了typeahead.js onselect项重定向到新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆