我目前正在开发一个SharePoint Online项目,我需要从Sharepoint列表中获取数据并填充html表。我正在使用脚本编辑器Web部件,并且已经尝试过此代码,但是未填充数据。它仅显示表头。
<html>
<head>
<SCRIPT type=text/javascript src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js"></SCRIPT>
<SCRIPT type=text/javascript src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.js"></SCRIPT>
<SCRIPT type=text/javascript src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js"></SCRIPT>
<script
src="https://code.jquery.com/jquery-1.4.2.min.js"
integrity="sha256-4joqTi18K0Hrzdj/wGed9xQOt/UuHuur+CeogYJkPFk="
crossorigin="anonymous"></script>
</head>
<body>
<table id="myHTMLTable" border=1 width="90%" align="center">
<tr align='left'>
<td><B>ID</B></td>
<td><B>PONumber</B></td>
<td><B>Location</B></td>
<td><B>Currency</B></td>
</tr>
</table>
<SCRIPT type=text/javascript>
getMyListData() ;
function getMyListData()
{
var method = "GetListItems";
var webURL = $().SPServices.SPGetCurrentSite() ;
var list = "Payment Requisition";
var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Title' />" +"</ViewFields>";
var query = "<Query><OrderBy><FieldRef Name='ID' Ascending='True' /></OrderBy></Query>";
$().SPServices
({
operation: method,
async: false,
webURL: webURL,
listName: list,
CAMLViewFields: "<ViewFields Properties='True' />",
CAMLQuery: query,
completefunc: function (xData, Status)
{
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
var ID = $(this).attr("ID");
var PONumber = $(this).attr("PONumber");
var Location = $(this).attr("Location");
var Currency = $(this).attr("Currency");
$("#myHTMLTable").append("<tr align='middle'>" +
"<td align='left'>"+ID+"</td>" +
"<td align='left'>"+PONumber+"</td>" +
"<td align='left'>"+Location+"</td>" +
"<td align='left'>"+Currency+"</td>" +
"</tr>");
});
}
});
};
</script>
</body>
</html>