开发者

Get selected item using JQuery AutoComplete

开发者 https://www.devze.com 2023-04-13 00:32 出处:网络
I have the code below working.How do I read and set the item selected to a control on the page (i.e. hidden field).NomineeUserName is a property on the object being returned.Thanks for any help provid

I have the code below working. How do I read and set the item selected to a control on the page (i.e. hidden field). NomineeUserName is a property on the object being returned. Thanks for any help provided.

$(function () {
$(".tb").autocomplete({
    source: functio开发者_JS百科n (request, response) {
        $.ajax({
            url: "/Service/NomineeWebService.asmx/GetMatchingActiveDirectoryUsers",
            data: "{ 'SearchCharacters': '" + request.term + "' }",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataFilter: function (data) { return data; },
            success: function (data) {
                response($.map(data.d, function (item) {
                    return {
                        id: item.NomineeUserName,
                        value: item.NomineeLastNameFirstName,
                        data: item
                    }
                }))
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
            }
        });
    },
    minLength: 2,
    select: function (event, ui) {
        selectedItemData = ui.item.data;
    }
});

});


In your select handler, it should be pretty simple:

select: function (event, ui) {
    $("hidden-input-selector").val(ui.item.id);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号