need gmail like functionailty - jquery autocomplete to include names and email addresses - in string searching

前端 未结 2 1431
萌比男神i
萌比男神i 2020-12-10 07:20

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

Need a good way for user to select "To" for email sending

相关标签:
2条回答
  • 2020-12-10 07:58

    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" }
    ];
    
    0 讨论(0)
  • 2020-12-10 08:13

    FYI, This "autocomplete" plugin is no longer in development, per a note on the webiste:

    http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

    jQuery plugin: Autocomplete

    Note (2010-06-23): This plugin is deprecated and not developed anymore. Its successor is part of jQuery UI, and this migration guide explains how to get from this plugin to the new one. This page will remain as it is for reference, but won’t be updated anymore.

    So if you want, you can use the following comparable example from the jQueryUI autocomplete:

    http://jqueryui.com/demos/autocomplete/#multiple-remote

    I personally prefer jQuery Tools to jQueryUI / but they don't offer an autocomplete plugin at this point... oh well.

    0 讨论(0)
提交回复
热议问题