来自谷歌电子表格的 JSON 数据 [英] JSON data from google spreadsheet

查看:34
本文介绍了来自谷歌电子表格的 JSON 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了这个小提琴,其中有一个包含 json 数据的三个下拉列表的示例.我有一个示例 google 这里的电子表格.现在可以将此电子表格数据呈现为在 fiddle 中以 json 格式给出的示例.我知道我们可以将电子表格转换为 json,

I went through this fiddle which have a sample of three dropdown with json data. I have a sample google spreadsheet here. Now is it possible to render this spreadsheet data to the example given at fiddle as json format. I know we can convert the spreadsheet to json as,

 var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=0AozvCNI02VmpdDkwR3RETmczbTI4ZFJhTXJkZHlUbEE#gid=0');
 query.send(handleQueryResponse);
 }
 function handleQueryResponse(response) {
    data = response.getDataTable();
    }

但是使用这个下拉菜单不起作用.

But using this the dropdown didn't works.

推荐答案

我不确定你的做法,但可以用不同的方式来完成.请使用您的示例数据查看this fiddle,以及下面的代码.

I'm not sure about the way you're doing it but it can be accomplished a different way. Please see this fiddle using your example data, and below for the code.

基本上,您可以使用以下 HTML 脚本标签从电子表格中调用 JSON 数据.

Basically you call the JSON data from your spreadsheet with the below HTML script tags.

<script src="http://spreadsheets.google.com/feeds/list/0An1-zUNFyMVLdEFEdVV3N2h1SUJOdTdKQXBfbGpNTGc/1/public/values?alt=json-in-script&amp;callback=importGSS"></script>

请注意,我正在链接到您电子表格的副本,因为它需要发布

Please note I'm linking to a copy of your spreadsheet as it requires it to by published

然后您可以使用以下脚本处理数据.

Then the you can handle the data with the below script.

function importGSS(json){
    for(var i = 0; i < json.feed.entry.length; i++){
        var entry = json.feed.entry[i];
        $('#departments').append('<option>' + entry.gsx$subdivision.$t + '</option>');
        $('#subject').append('<option>' + entry.gsx$section.$t + '</option>');
        $('#services').append('<option>' + entry.gsx$station.$t + '</option>');
    }
}

您显然可以适应自己的需求.

You can obviously adapt to your own needs.

这篇关于来自谷歌电子表格的 JSON 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆