REST API多选字段返回[对象对象]而不是实际选择-SharePoint Online

时间:2019-09-24 07:49:54

标签: sharepoint sharepoint-2010 office365 sharepoint-2013 sharepoint-online

我有一个REST API,它返回多选字段值作为[object Object]而不是实际值。

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> 

1 个答案:

答案 0 :(得分:0)

您的选择列是一个对象。您需要遍历对象的内容。例如,选择字段(而不是下拉选择字段)是字符串数组。

观察/记录变量arrayOfAllData[i].Action_x0020_By_x003a_,您应该能够弄清楚如何遍历数据。