需要类似功能的 gmail - jquery 自动完成以包含姓名和电子邮件地址 - 在字符串搜索中 [英] need gmail like functionailty - jquery autocomplete to include names and email addresses - in string searching

查看:7
本文介绍了需要类似功能的 gmail - jquery 自动完成以包含姓名和电子邮件地址 - 在字符串搜索中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近问了这个问题,并得到了一个使用 jquery 进行自动完成的很好的解决方案:

I recently asked this question and got back a great solution using jquery for autocomplete:

需要一个好方法用户选择到"用于发送电子邮件

解决方案是使用以下语法:

The solution was to use this syntax:

$("#suggest3").autocomplete(someArray, {
    multiple: true,
    mustMatch: true,
    autoFill: true

});

我现在对电子邮件地址列表具有自动完成功能,我需要更进一步映射到类​​似于 gmail 的功能,其中我在列表中包含真实"姓名和电子邮件地址,以便用户可以输入姓名或电子邮件地址,它会找到条目:

i now have autocomplete on a list of email addresses and i need to take it one step further to map onto gmail like functionality where i include both the "real" name and the email address in the list so users can enter either the name or the email address and it will find the entry:

因此列表看起来与此类似,用户可以通过键入Firs .."进行搜索.或电子邮件添加..."

So the list would look similar to this and the user can search by typing "Firs . . ." or "emailAdd..."

"First Last" <emailAddress>   
"First1 Las1t" <emailAddress1>   
"First2 Last2" <emailAddress2>   

推荐答案

等一下.. 你看了吗 演示?我认为它已经做到了这一点.例如,如果我在电子邮件字段中输入for"或jap",就会出现同一个人:Fornelia Marconi(jap"是她电子邮件地址的一部分).这是启用此功能的代码.

Wait a second.. Did you look at the demo? I think it already does exactly this. For instance, if I type in "for" or "jap" into the e-mail field, the same person shows up: Fornelia Marconi (with "jap" being part of her e-mail address). Here is the code that enables this.

$("#thickboxEmail").autocomplete(emails, {
    minChars: 0,
    width: 310,
    matchContains: true,
    highlightItem: false,
    formatItem: function(row, i, max, term) {
        return row.name.replace(new RegExp("(" + term + ")", "gi"), "<strong>$1</strong>") + "<br><span style='font-size: 80%;'>Email: &lt;" + row.to + "&gt;</span>";
    },
    formatResult: function(row) {
        return row.to;
    }
});

姓名-电子邮件对数组如下所示:

The array of name-e-mail pairs looks like this:

var emails = [
    { name: "Peter Pan", to: "peter@pan.de" },
    { name: "Molly", to: "molly@yahoo.com" }
];

这篇关于需要类似功能的 gmail - jquery 自动完成以包含姓名和电子邮件地址 - 在字符串搜索中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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