javascript - How to bind json string containing key value pairs to autocomplete jquery textbox? -


i getting json string in form

[{"name":"hassi","email":"sx_sem@hotmail.com"},   {"name":"hass","email":"sx_sem@hotmail.com"}, {"name":"sam","email":"xxx_sem@hotmail.com"}] 

i following example given @ jquery-ui http://jqueryui.com/autocomplete/#multiple

i trying multiple values autocomplete email application. want show in format when user type name, autocomplete show thename+emails , on selection should show email. unlucky in doing so.

this code:

  function split(val) {        return val.split(/,\s*/);   }   function extractlast(term) {         return split(term).pop();   }       $("#<%=txtemail.clientid%>")        // don't navigate away field on tab when selecting item        .bind("keydown", function (event) {        if (event.keycode === $.ui.keycode.tab &&           $(this).autocomplete("instance").menu.active) {             event.preventdefault();        }      })      .autocomplete({          minlength: 0,          source: function (request, response) {            // delegate autocomplete, extract last term            response($.ui.autocomplete.filter(            jsondata, extractlast(request.term)));            // when jsondata whole json string displaying,            //i want show concatenate name + email          },          focus: function () {            // prevent value inserted on focus            return false;          },          select: function (event, ui) {            var terms = split(this.value);            // remove current input            terms.pop();            // add selected item            terms.push(ui.item.email);            // add placeholder comma-and-space @ end            terms.push("");            this.value = terms.join(", ");            return false;           }          }); 


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -