I'm pulling data out of a Google Spreadsheet to display on an HTML page in 
a table. Here's my code:

<!DOCTYPE html><html lang='en'>
<head><meta charset='utf-8'>
<script type='text/javascript' 
src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>
<script>function displayContent(json) {
    var len = json.feed.entry.length
    var pretable = 
'<table><thead><tr><th>Name</th><th>Points</th></tr></thead><tbody>'
    var table = ''
    var posttable = '</tbody><//table>'
    for (var i=1; i<len; i++) {
        table += [
            '<tr><td>',
            json.feed.entry[i].gsx$name.$t,
            '</td><td>',
            json.feed.entry[i].gsx$points.$t,
            '</td></tr>'
            ].join('');  
            }
    document.getElementById('results').innerHTML = pretable + table + posttable
        }
</script>
</head>
<body>
<div id="results"></div>
<script 
src="http://spreadsheets.google.com/feeds/list/0Ag4MM37uq7FmdDJEOVFPaDlZSHYzRjYzcHZ0aUpvY3c/od6/public/values?alt=json-in-script&amp;callback=displayContent
 
<http://spreadsheets.google.com/feeds/list/0Ag4MM37uq7FmdDJEOVFPaDlZSHYzRjYzcHZ0aUpvY3c/od6/public/values?alt=json-in-script&callback=displayContent>"
 type="text/javascript"></script>
</body>
</html>

And here's the 
spreadsheet<https://docs.google.com/spreadsheet/ccc?key=0Ag4MM37uq7FmdDJEOVFPaDlZSHYzRjYzcHZ0aUpvY3c&usp=sharing>
.

So, that all works. What I'm trying to do now is write a function that will 
loop through the *gameid* column and, for each entry, return the number of 
times that entry occurs. So, for example, given an input of

json.feed.entry[5].gsx$gameid.$t

, the function would return 4, because *123 *occurs four times. Then I want 
to store that result as a variable to access later.

Based on a Stackoverflow answer, I tried inserting into my for loop:

    var count = {};
$.each(json.feed.entry[i].gsx$gameid.$t, function(){
    var num = this[0];
    count[num] = count[num]+1 || 1;});

... but when I tried to access the variable *count*, I got:

Uncaught TypeError: Cannot use 'in' operator to search for '2' in 456.

Maybe this is the wrong approach. Any solutions? Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-spreadsheets-api+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to