I am using the following code to pull back items from a SharePoint List
function getItems(url) {
return $.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
}
});
}
getItems( "/_api/Web/Lists/GetByTitle('Reporting%
20Listing')/Items" ).done(function(data){
data.d.results.forEach(function(item){
console.log( item.ID, item.Title, item.ApprovalName,
item.ApprovalDate );
});
});
This is working fine except item.ApprovalName
is not returning any value.
Do I need to somehow reference which element of the ApprovalName
array that I want? I've looked through several reference but don't see an example.
Sample demo to expand multiuser field.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
SP.SOD.executeOrDelayUntilScriptLoaded(GetListItems, "sp.js");
function GetListItems() {
var apiPath = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('MyList3')/items?$select=Title,MultiUsers/Name,MultiUsers/EMail&$expand=MultiUsers";
$.ajax({
url: apiPath,
headers: {
Accept: "application/json;odata=verbose"
},
async: false,
success: function (data) {
if (data != null) {
for (var i = 0; i < data.d.results.length; i++) {
console.log(data.d.results[i].Title);
for (var j = 0; j < data.d.results[i].MultiUsers.results.length; j++) {
console.log(data.d.results[i].MultiUsers.results[j].Name);
}
}
}
},
eror: function (data) {
console.log("An error occurred. Please try again.");
}
});
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.