Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

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

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.

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>
question from:https://stackoverflow.com/questions/65849416/using-fetch-to-pull-sharepoint-list-items

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to use return fullUrl as variable name

fetch(fullUrl) 

You have used fetch('fullUrl'), which is just a string fullUrl.

Do also call your 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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...