自动完成选择重定向 [英] Autocomplete Select Redirect

查看:71
本文介绍了自动完成选择重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在自动完成项上选择的项目上重定向页面.我正在使用JSON填充自动完成功能.如何获得它以从JSON重定向到具有ID的URL?我尝试使用选择功能,但这似乎不起作用.选择项目时甚至都不会转到URL.任何帮助将不胜感激!

I am trying to redirect the page on the selection of an item on autocomplete. I am using JSON to populate the autocomplete. How can I get it to redirect to a URL with the ID from the JSON? I tried using the select function but that doesn't seem to work. It is not even going to a URL when selecting an item. Any help would be greatly appreciated!

 <script type="text/javascript">
    $(function() {

        $('#user').autocomplete({
            minLength: 2,
            source: '<%= admin_users_path(:json) %>',
            focus: function(event, ui) {
                $('#user').val(ui.item.first_name + " " + ui.item.last_name);
                return false;
            },
            select: function(event, ui) {   
                location.href="/admin/users/" + val(ui.item.id) + "/edit";
            }
        })

        .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
          return $( "<li>" )
            .data( "ui-autocomplete-item", item )
            .append( "<a>" + item.first_name + " " + item.last_name  + "</a>" )
            .appendTo( ul );
        };
    });
</script>

推荐答案

如果我更改此设置,它将起作用.

If I change this, it works.

            select: function(event, ui) {   
                location.href="/admin/users/" + ui.item.id + "/edit";
            }

这篇关于自动完成选择重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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