如何获得正确格式化的自动完成数据

本文关键字:数据 何获得 格式化 | 更新日期: 2023-09-27 17:50:41

使用。net这是我得到的。返回正确的结果,但是它们都被组合成一个长字符串。我怎样才能从返回的结果中每次选择一个项目?我知道我的源代码在javascript中配置不正确。任何帮助都会很感激。由于

背后的代码:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetEmails(string emailContains)
{
    LoginSet logins = staticLogic.searchLogins(staticClient, new SearchCriteriaSet());
    List<BaseEntry> loginList = logins.Where(x => ((LoginEntry)x).LoginEMail.Contains(emailContains)).ToList();
    List<string> emails = new List<string>();
    for (int i = 0; i < loginList.Count(); ++i)
    {
        string email = ((LoginEntry)loginList.ElementAt(i)).LoginEMail;
        emails.Add(email);
    }
    //JavaScriptSerializer serializer = new JavaScriptSerializer();
    //string json = serializer.Serialize(emails.ToArray());
    return emails.ToArray();
}
UI:

<tr><td>Destination:</td>
    <td>
        <div class="ui-widget">
            <input type="text" name="EMailReportDestination" id="EMailReportDestination" size="60" runat="server" />
        </div>
    </td>
</tr>
JQuery:

        $('#EMailReportDestination').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '/reports/editemailreport.aspx/GetEmails',
                    type: 'POST',
                    dataType: 'json',
                    data: "{'emailContains':'" + request.term + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },
                    success: function (data) {
                        //console.log('autocomplete success: ' + data);
                        response($.map(data, function (item) {
                            return {
                                label: item,
                                value: item
                            }
                        }));
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        console.log("autocomplete error: " + xhr.status + ", " + thrownError);
                    }
                });
            },
            minLength: 2,
            select: function (event, ui) {
                console.log(ui.item ? "selected: " + ui.item.label : "nothing selected, input was " + this.value);
            },
            open: function () {
                $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
            },
            close: function () {
                $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
            }
        });

如何获得正确格式化的自动完成数据

我试过了,我不知道在data.d中返回的数组。尝试更改

response($.map(data, function (item) 

 response($.map(data.d, function (item)