将用户重定向上选择从自动完成? [英] Redirecting users on select from autocomplete?

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

问题描述

我想要实现jQuery的自动完成插件。
我有它运行起来,但事情不能正常工作。

基本上我有员工的自动完成列表。
从表中一个SQL数据库(employee_names和EMPLOYEE_ID)生成的列表,使用VB.NET处理程序(ashx的文件)。该数据的格式为:employee_name-EMPLOYEE_ID。到目前为止好和所有的员工都在自动完成上市。

问题是,我不知道如何将用户重定向到某个页面(例如employee_profile.aspx)时,他们已经从自动完成所选的员工。

这是我的redirect- code,但它不工作像它应该:

  $('#fname2')。结果(函数(事件,数据格式){
        location.href =employee_profile.aspx?ID =+数据
});

例如;一个用户选择
这将用户重定向到 employee_profile.aspx ID =员工的员工ID的名称?(例如:employee_profile.aspx ID =李四-91210),而不是employee_profile.aspx ID = 91210?

我知道我可以剥夺与EMPLOYEE_ID:

  formatResult:功能(数据,值){
   返回value.split( - )[1];
   }
});

但我不知道如何说EMPLOYEE_ID传递给重定向页面。

下面我整个code:

  $()。就绪(函数(){        $(#fname2)。自动完成(AutocompleteData.ashx,{
            minChars:3,
            selectFirst:假的,
            formatItem:功能(数据,I,N,价值){
            返回value.split( - )[0];
            },
            //未使用,只是为了分裂EMPLOYEE_ID
            // formatResult:功能(数据,值){
            //返回value.split( - )[1];
            //}
            });            $('#fname2')。结果(函数(事件,数据格式){
            location.href =employee_profile.aspx?ID =+数据
            });    });

我知道我非常接近,它应该是很简单的东西,但任何人都可以帮我吗?

修改

这解决了我:formatted.split而不是data.split。
code:

  $('#fname3')。结果(函数(事件,数据格式){
            变种雇员= formatted.split( - )[1];
            location.href =employee_profile.aspx?ID =+雇员
});


解决方案

你是说,它是成功的,但是重定向而不是去......

employee_profile.aspx?ID = 91210

这是要......

employee_profile.aspx?ID =李四-91210 ??

如果是这样的话...那么你可以简单地你的结果函数中执行您的条带化...

  $('#fname2')。结果(函数(事件,数据格式){
        变种雇员= data.split( - )[1];
        location.href =employee_profile.aspx?ID =+雇员
 });

i'm trying to implement the jquery autocomplete plugin. I've got it up and running, but something is not working properly.

Basically i have a autocomplete-list of employees. The list is generated from a table in a sql-database (employee_names and employee_ID), using a VB.NET handler (.ashx file). The data is formatted as: employee_name-employee_ID. So far so good and all employees are listed in autocomplete.

The problem is that i don't know how to redirect a user to a certain page (for example employee_profile.aspx) when they've selected an employee from autocomplete.

This is my redirect-code, but it ain't working like it should:

$('#fname2').result(function(event, data, formatted) {
        location.href = "employee_profile.aspx?id=" + data
});

For example; a user selects It will redirect a user to employee_profile.aspx?id=name of employee-id of employee (for example: employee_profile.aspx?id=John Doe-91210) instead of employee_profile.aspx?id=91210.

I know i can strip the employee_ID with:

formatResult: function(data, value) {
   return value.split("-")[1];
   }   
});

But i do not know how to pass that employee_ID to the redirect-page..

Here my whole code:

$().ready(function() {

        $("#fname2").autocomplete("AutocompleteData.ashx", {
            minChars: 3,
            selectFirst: false,
            formatItem: function(data, i, n, value) {
            return value.split("-")[0];
            },
            //Not used, just for splitting employee_ID
            //formatResult: function(data, value) {
            //   return value.split("-")[1];
            //}  
            });

            $('#fname2').result(function(event, data, formatted) {
            location.href = "employee_profile.aspx?id=" + data
            });

    });

I know i'm very close and it should be something really simple, but can anyone help me out?

EDIT

This solved it for me: formatted.split instead of data.split. Code:

$('#fname3').result(function(event, data, formatted) {
            var employeeId = formatted.split("-")[1];
            location.href = "employee_profile.aspx?id=" + employeeId
});

解决方案

Are you saying that it is successfully redirecting but rather than going to...

employee_profile.aspx?id=91210

It is going to...

employee_profile.aspx?id=John Doe-91210 ??

If that is the case... then you can simply perform your striping inside your result function...

$('#fname2').result(function(event, data, formatted) {
        var employeeId = data.split("-")[1];
        location.href = "employee_profile.aspx?id=" + employeeId
 });

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

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