我收到了
形式的json字符串[{"Name":"Hassi","Email":"sx_sem@hotmail.com"},
{"Name":"Hass","Email":"sx_sem@hotmail.com"},
{"Name":"Sam","Email":"xxx_sem@hotmail.com"}]
我正在关注jquery-ui http://jqueryui.com/autocomplete/#multiple
中给出的示例我正在为我的电子邮件应用程序执行multiple values autocomplete
。但我希望以用户类型名称显示格式,自动填充功能会显示name+emails
和on selection
,它应该只显示email
。但我这样做是不吉利的。
这是我的代码:
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$("#<%=txtEmail.ClientID%>")
// don't navigate away from the field on tab when selecting an 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 back to autocomplete, but extract the last term
response($.ui.autocomplete.filter(
jsonData, extractLast(request.term)));
// When i am jsonData the whole json string is displaying,
//I only want to show concatenate name + email
},
focus: function () {
// prevent value inserted on focus
return false;
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.email);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
});