My sheet: https://docs.google.com/spreadsheets/d/1pruXYXrbITR7CoQXZG1I1kyS4DahYBXmGMDEK2T6MpY/edit?usp=sharing
I'm using Google sheets JSON data to display on my website but I want to put some of the data into arrays so it doesn't repeat itself on the website.
For example, this is how it displays, but I would like to be able to just have the one heading for each group (zouk, zen ect) and then all the members to be under the one header. https://www.kentunion.co.uk/test1/
So I am trying to figure out some javascript that adds all the positions of one group into an array. Go from this:
"Zouk Society" : {
"name" : "Zouk Society",
"position" : "President",
"member" : "Currently Vacant"
},
"Zouk Society" : {
"name" : "Zouk Society",
"position" : "Secretary",
"member" : "Currently Vacant"
},
"Zouk Society" : {
"name" : "Zouk Society",
"position" : "Treasurer",
"member" : "Currently Vacant"
}
to this:
"Zouk Society" [{
"position" : "President",
"member" : "Currently Vacant"
},
{
"position" : "Secretary",
"member" : "Currently Vacant"
},
{
"position" : "Treasurer",
"member" : "Currently Vacant"
}
]
I have tried the following JS but I am just getting an error from it:
// ID of the Google Spreadsheet
var spreadsheetID = "1pruXYXrbITR7CoQXZG1I1kyS4DahYBXmGMDEK2T6MpY";
// Make sure it is public or set to Anyone with link can view
var url = "https://spreadsheets.google.com/feeds/list/1pruXYXrbITR7CoQXZG1I1kyS4DahYBXmGMDEK2T6MpY/od6/public/values?alt=json";
$(document).ready(function () {
$.getJSON(url, function(data) {
var entry = data.feed.entry;
$(entry).each(function(){
// Column names are name, age, etc.
$('.results').prepend('<h2>'+this.gsx$name.$t+'</h2><p>'+this.gsx$position.$t+'</p><p>'+this.gsx$member.$t+'</p>');
});
});
var grouped = {};
entry.forEach(function (a) {
grouped[a.name] = grouped[a.name] || [];
grouped[a.name].push({ position: a.position, member: a.member });
});
document.write('<pre>' + JSON.stringify(grouped, 0, 4) + '</pre>');
});
This is the error that I get:
Uncaught ReferenceError: entry is not defined at HTMLDocument. (scripts.js:19)