开发者

Get selected item using JQuery AutoComplete

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜