Created
November 9, 2016 14:24
-
-
Save LayneSmith/bcdbde8567779e8335fb93f6edd3db2a to your computer and use it in GitHub Desktop.
Retrieve Google Spreadsheets content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function buildList(spreadsheet) { | |
| $.getJSON("https://spreadsheets.google.com/feeds/list/" + spreadsheet + "/od6/public/values?alt=json", function (data) { | |
| //Insert the hed and dek divs. | |
| $('#listContainer').html('<div id="hed"></div><div id="deck"></div>'); | |
| //In console, you can see what info is being returned so you know how to get at the info you need. Remove for deployment. | |
| //console.log(data); | |
| //Find the total number of rows being delivered | |
| var totalEntries = data.feed.entry.length; | |
| //Creat an array where only the content you want will live | |
| var contentArray = new Array(); | |
| //Add hed copy | |
| var hed = data.feed.entry[0].gsx$text.$t; | |
| $("#listContainer #hed").append(hed); | |
| //Add dek copy | |
| var deck = data.feed.entry[1].gsx$text.$t; | |
| $("#listContainer #deck").append(deck); | |
| //FOR loop parses the data and fills the array from above | |
| for (var i = 2; i < totalEntries; i++) { | |
| //Filling the array... | |
| contentArray[i] = [data.feed.entry[i].gsx$link.$t, data.feed.entry[i].gsx$text.$t, data.feed.entry[i].gsx$credit.$t]; | |
| //jQuery: append the following string to the div with the class | |
| $("#listContainer").append("<div class='box'><div class='number'>" + (i - 1) + "</div><img src=" + contentArray[i][0] + " width='100%'><div class='credit'>" + contentArray[i][2] + "</div><div class='textBox'>" + contentArray[i][1] + "</div></div>"); | |
| }; | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment