需要类似功能的 gmail - jquery 自动完成以包含姓名和电子邮件地址 - 在字符串搜索中 [英] need gmail like functionailty - jquery autocomplete to include names and email addresses - in string searching
问题描述
我最近问了这个问题,并得到了一个使用 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: <" + row.to + "></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屋!