REST API - filter choice field
-
14-01-2021 - |
質問
How do you go about filtering the list using items from multi value field? For example: If current user is the timekeeper for UnitA and UnitB, I want to filter another list to display only items from UnitA and UnitB.
Choice field name: UnitNames
I currently have the following to get the UnitNames:
var requestUri = webAbsUrl + "/_api/web/Lists/getByTitle('Directory')/Items?$\
filter=Title eq '" + currentUserEmail + "'&$\
select=Id, UnitNames";
var ajax = $.ajax({
url: requestUri,
async: false,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var countAjaxOrg = data.d.results.length;
if(countAjaxOrg > 0) {
var myUnitGroup = data.d.results[0].UnitNames;
}
},
error: function (data) { alert("Failed to load data."); }
});
I tried a simple alert alert(myUnitGroup);
and it returns [object Object]
. I need to filter another list with whatever values are returned from above but I cant figure out how to retrieve values from choice field.
解決
I believe you have to add ".results" to the end of your call if you're using SP2013 or above:
var myUnitGroup = data.d.results[0].UnitNames.results;
所属していません sharepoint.stackexchange