在提供程序托管的Web表单中加载Sharepoint列表,可以通过以下步骤实现:
示例代码如下:
<script type="text/javascript" src="/_layouts/15/init.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.Runtime.js"></script>
<script type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
var siteUrl = 'https://yoursharepointsiteurl';
var listName = 'YourListName';
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(listName);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>10</RowLimit></View>');
var collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(
function() {
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
console.log(oListItem.get_item('Title'));
}
},
function(sender, args) {
console.log(args.get_message());
}
);
});
</script>
示例代码如下:
<script type="text/javascript">
var siteUrl = 'https://yoursharepointsiteurl';
var listName = 'YourListName';
var url = siteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items";
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.setRequestHeader('Accept', 'application/json;odata=nometadata');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
var items = response.value;
for (var i = 0; i < items.length; i++) {
console.log(items[i].Title);
}
}
};
xhr.send();
</script>
以上是在提供程序托管的Web表单中加载Sharepoint列表的基本步骤。根据具体需求,你可以进一步扩展功能,例如添加筛选、排序、分页等功能。另外,腾讯云提供了云开发(CloudBase)服务,可以帮助你快速搭建和部署Web应用,具体产品介绍和相关文档可以参考腾讯云云开发官网:https://cloud.tencent.com/product/tcb
领取专属 10元无门槛券
手把手带您无忧上云