gpt4 book ai didi

javascript - 通过 Js 检索 Sharepoint 列表

转载 作者:行者123 更新时间:2023-11-30 09:10:43 24 4
gpt4 key购买 nike

我创建了一个包含四列的共享点列表。我将它们命名如下:姓名、职位、办公室、薪水。你能帮我如何从我的列表中检索项目(使用 JavaScript)吗?

最佳答案

您可以在需要替换站点 url、列表和列的地方使用以下示例代码:

使用 JavaScript 编码获取 SharePoint 列表项:

var siteUrl = 'https://siteUrl';
var listName= 'MyCustomListName';

function retrieveListItems()
{
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(listName);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
'<Value Type=\'Number\'>1</Value></Geq>
</Where></Query><RowLimit>10</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
}
functiononQuerySucceeded(sender, args)
{


var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nName: ' + oListItem.get_item('Name') +
'\nPosition: ' + oListItem.get_item('Position')+
'\nOffice: ' + oListItem.get_item('Office') +
'\nSalary: ' + oListItem.get_item('Salary');
}
alert(listItemInfo.toString());
}
functiononQueryFailed(sender, args)
{
alert('Request failed. ' +args.get_message() + '\n' + args.get_stackTrace());
}

使用 REST API 编码获取 SharePoint 列表项:

function retriveListItem()                                                
{
var resultGridHtmlMySubmission=''
$.ajax (
{
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('<SampleListName(yourlistTitle)>')/items?$select=Title,Name,Position,Office,Salary",
type: "GET",
data: JSON.stringify,
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": null
},
cache: false,
success: function(data)
{
for (vari = 0; i<data.d.results.length; i++)
{
var item = data.d.results[i];
resultGridHtmlMySubmission+='<tr>';
resultGridHtmlMySubmission+='<tdalign="center" valign="middle"><span title="Sr.No."><b>'+item.Title+'</b></span></td>';
resultGridHtmlMySubmission+='<td align="center" valign="middle"><span title="Sr.No."><b>'+item.Name+'</b></span></td>';
resultGridHtmlMySubmission+='<td align="center" valign="middle"><span title="Sr.No."><b>'+item.Position+'</b></span></td>';
resultGridHtmlMySubmission+='<td align="center" valign="middle"><span title="Sr.No."><b>'+item.Office+'</b></span></td>';
resultGridHtmlMySubmission+='<td align="center" valign="middle"><span title="Sr.No."><b>'+item.Salary+'</b></span></td>';
resultGridHtmlMySubmission+='</tr>';

}
$("#tbodycontent").html(resultGridHtmlMySubmission);
},
error: function(data)
{
// $("#ResultDiv").empty().text(data.responseJSON.error);
}
});
}

引用网址:

http://ramdotnetdeveloper.blogspot.com/2016/08/crud-operation-in-sharepoint-2013.html?m=1

关于javascript - 通过 Js 检索 Sharepoint 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59336343/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com