簡體   English   中英

使用 Fetch 拉取 SharePoint 列表項

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM