简体   繁体   English

使用 Fetch 拉取 SharePoint 列表项

[英]Using Fetch to Pull SharePoint List Items

I am trying to pull SharePoint List Data as JSON so I can populate it to a JavaScript template library.我正在尝试将 SharePoint 列表数据提取为 JSON 以便我可以将其填充到 JavaScript 模板库中。

I have used this script to test in a SharePoint Script Editor just to make sure the JSON posts to the console, and nothing is posted to the console and no errors appear.我已使用此脚本在 SharePoint 脚本编辑器中进行测试,以确保 JSON 发布到控制台,并且没有任何内容发布到控制台并且没有出现错误。

Here is my fetch script:这是我的获取脚本:

<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>

You have to use return fullUrl as variable name您必须使用 return fullUrl作为变量名

fetch(fullUrl) 

You have used fetch('fullUrl') , which is just a string fullUrl .您使用了fetch('fullUrl') ,它只是一个字符串fullUrl

Do also call your function getItems();也请致电您的 function getItems();

Your Code should look like this:您的代码应如下所示:

 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