langus
11/22/2013 - 10:47 AM

Kontrolka wyszukjąca za pomoca rest

Kontrolka wyszukjąca za pomoca rest

    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Kontrahenci')/items";

    $('#'+ContractorField._containerId).autocomplete({
        source: function (request, response) {
            $.ajax({
                type: "GET",
                url: requestUri + "?$filter=startswith(Title,'" + request.term + "')&$select=Title,Id",
                contentType: "application/json",
                headers: { Accept: "application/json;odata=verbose" },
                success: function (data) {
                    response($.map(data.d.results, function (item) {
                        return {
                            label: item.Title,
                            value: item.Id
                        }
                    }))
                }
            })
        },
        minLength: 3,
                select: function (event, ui) {
            event.preventDefault();
            $('#' + ContractorField._containerId).val(ui.item.label);
        },
        focus: function (event, ui) {
            event.preventDefault();
            $('#' + ContractorField._containerId).val(ui.item.label);
        }
    });