如何解决如何在 webpart 属性 spfx 的下拉列表中获取 SharePoint 在线站点中存在的各种列表
下面是我正在使用的方法,我在下面的方法中做错了什么? 请告诉我。
private async GetLists(): Promise<any>
{
console.log("Hitting GetLists Method");
return await
this.context.spHttpClient.get(`${this.context.pageContext.web.absoluteUrl}/_api/web/lists`,SPHttpClient.configurations.v1,{
headers: [
['accept','application/json;odata=noMetadata'],['odata-version','']
]
}).then((data) =>
{
//console.log("Total number of lists are " + data.length);
return data;
});
}
解决方法
我的测试代码供您参考:
private GetLists(): Promise<any> {
return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + "/_api/web/lists",SPHttpClient.configurations.v1,{
headers: [
['accept','application/json;odata=nometadata'],['odata-version','']
]
})
.then((response: SPHttpClientResponse) => {
return response.json();
}).then(response=>console.log(response));
}
,
尝试使用 PnPjs:
private GetLists(): Promise<any> {
return sp.web.lists.get().then((data) => {
console.log("Total number of lists are " + data.length);
return data;
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。