У меня есть REST API, который возвращает значение поля с множественным выбором как [объектный объект] вместо фактического значения.
tableContent + = '' + arrayOfAllData [i] .Action_x0020_By_x003a_ + '';
Поле Action_x0020_By_x003a_ является полем с множественным выбором в Office365.Я попытался использовать arrayOfAllData [i] .Action_x0020_By_x003a_.choices.results, а также arrayOfAllData [i] .Action_x0020_By_x003a_.results, но оно вернулось неопределенным.Также использовал некоторую карту, но не работает.Любой совет будет полезен
<script src="https://dev.sharepoint.com/sites/dev/SiteAssets/jquery-1.10.2.js"></script>
<script src="https://dev.sharepoint.com/sites/dev/SiteAssets/jquery.min.js"></script>
<script>
var ListDataCollection = {
Lists:[{
Url:"https://dev.sharepoint.com/sites/dev/sites1/_api/web/lists/getbytitle('Employee')/items?$top=5&$orderby=Created desc&$select=Title,Description,Action_x0020_By_x003a_,RequestFrom_x003a_,Created&$filter=Category eq 'Key Events and Decision'",
Completed:false
},{
Url:"https://dev.sharepoint.com/sites/dev/sites2/_api/web/lists/getbytitle('Employee')/items?$top=5&$orderby=Created desc&$select=Title,Description,Action_x0020_By_x003a_,RequestFrom_x003a_,Created&$filter=Category eq 'Key Events and Decision'",
Completed:false
},{
Url:"https://dev.sharepoint.com/sites/dev/sites3/_api/web/lists/getbytitle('Employee')/items?$top=5&$orderby=Created desc&$select=Title,Description,Action_x0020_By_x003a_,RequestFrom_x003a_,Created&$filter=Category eq 'Key Events and Decision'",
Completed:false
}]
};
var tableContent = '<table id="tableEmployee" style="width:100%" border="1 px"><thead><tr><td><b>No</b></td>' +
'<td><b>Description</b></td>' + '<td><b>Action By</b></td>' + '<td><b>Request From</b></td>' + '<td><b>Created</b></td>'+
'</tr></thead><tbody>';
function groupBy(items,propertyName)
{
var result = [];
$.each(items, function(index, item) {
if ($.inArray(item[propertyName], result)==-1) {
result.push(item[propertyName]);
}
});
return result;
}
function RemoveDuplicateItems(items, propertyName) {
var result = [];
$.each(items, function (index, item) {
if ($.inArray(item[propertyName], result) == -1) {
result.push(item[propertyName]);
}
});
return result;
}
function ifAllCompleted() {
for (var i=0;i<ListDataCollection.Lists.length;i++) {
if (!ListDataCollection.Lists[i].Completed) {
return false;
}
}
console.log('Completed');
var arrayOfAllData = ListDataCollection.Lists[0].Data.d.results;
arrayOfAllData = arrayOfAllData.concat(ListDataCollection.Lists[1].Data.d.results);
arrayOfAllData = arrayOfAllData.concat(ListDataCollection.Lists[2].Data.d.results);
console.log('Total elements : ' + arrayOfAllData.length);
arrayOfAllData=RemoveDuplicateItems(arrayOfAllData,'Description')
for( var i=0; i<arrayOfAllData.length;i++)
{
tableContent += '<tr>';
tableContent += '<td>' + arrayOfAllData[i].Title+ '</td>';
tableContent += '<td>' + arrayOfAllData[i].Description+ '</td>';
tableContent += '<td>' + arrayOfAllData[i].Action_x0020_By_x003a_+ '</td>';
tableContent += '<td>' + arrayOfAllData[i].RequestFrom_x003a_+ '</td>';
tableContent += '<td>' + arrayOfAllData[i].Created+ '</td>';
tableContent += '</tr>';
}
$('#employeeGrid').append(tableContent);
}
$(document).ready(function(){
for (var x=0;x<ListDataCollection.Lists.length;x++) {
$.ajax({
url:ListDataCollection.Lists[x].Url,
indexValue:x,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data, status, xhr) {
ListDataCollection.Lists[this.indexValue].Data = data;
ListDataCollection.Lists[this.indexValue].Completed = true;
ifAllCompleted();
},
error: function (xhr, status, error) {
console.log('error');
}
});
}
});
</script>
<div id="CustomerPanel">
<table id="tableEmployee" border="1 px" style="width: 100%;">
<tbody>
<tr>
<td>
<div id="employeeGrid" style="width: 100%;"><br /><br /><br /><br /><br /></div>
</td>
</tr>
</tbody>
</table>
</div>