![](/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.