![](/img/trans.png)
[英]Item is undefined when using SPServices to fetch items from Sharepoint list
[英]Using Fetch to Pull SharePoint List Items
我正在尝试将 SharePoint 列表数据提取为 JSON 以便我可以将其填充到 JavaScript 模板库中。
我已使用此脚本在 SharePoint 脚本编辑器中进行测试,以确保 JSON 发布到控制台,并且没有任何内容发布到控制台并且没有出现错误。
这是我的获取脚本:
<script>
var fullUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('WeeklyReport1')/items?$select=Team,WeekOf,OffensiveReport,DefensiveReport,SpecialTeamsReport";
const getItems = () => {
return fetch('fullUrl')
.then(res => res.json())
.then(posts => console.log(posts))
}
</script>
您必须使用 return fullUrl
作为变量名
fetch(fullUrl)
您使用了fetch('fullUrl')
,它只是一个字符串fullUrl
。
也请致电您的 function getItems();
您的代码应如下所示:
var fullUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('WeeklyReport1')/items?$select=Team,WeekOf,OffensiveReport,DefensiveReport,SpecialTeamsReport";
const getItems = () => {
return fetch(fullUrl)
.then(res => res.json())
.then(posts => console.log(posts))
}
getItems();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.