从 YQL 生成的 JSON 数组中获取第 n 行

发布于 2024-12-16 18:20:02 字数 1289 浏览 5 评论 0原文

我正在使用 YQL 获取并显示 Google 电子表格中的数据,如下所示:

http://jsfiddle.net/ weCve/1/

我想显示多个查询的复合 YQL 查询的结果,并在单独的无序列表中显示结果。

我的复合查询是 这里。 小提琴在这里: http://jsfiddle.net/svh2r/1/

我的问题是,我必须对这条线做什么才能让它占据某一行?

$.each(data.query.results.results.row, function (i, item) {

我以为会这样,

data.query.results.results.row[1]

但那行不通。

I'm using YQL to get and display data from a Google spreadsheet, like this:

http://jsfiddle.net/weCve/1/

I'd like to display results from a composite YQL query of multiple queries, and show the results in separate unordered lists.

My composite query is here.
and a fiddle is here: http://jsfiddle.net/svh2r/1/

My question is, what do I have to do to this line in order to get it to take a certain row?

$.each(data.query.results.results.row, function (i, item) {

I thought it would be

data.query.results.results.row[1]

but that doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我恋#小黄人 2024-12-23 18:20:02

data.query.results.results 是一个数组,其中包含来自单独查询的每个结果集。您可以通过 data.query.results.results[n] 单独访问它们,其中 n012 (对应于您的三个查询)。

要循环第二个查询的结果(结果数组中的偏移量 1),您可以这样做:

$.each(data.query.results.results[1].row, function (i, item) { … });

使用两个 $.each 可能(也可能没有)有用循环遍历所有结果中的所有行。

$.each(data.query.results.results, function (i, results) {
    $.each(results.row, function (i, item) {
         // do something
    });
});

以下是示例代码的改编版本,经过修改以构建三个列表 - http://jsfiddle.net/XfBsj/

data.query.results.results is an array containing each of the result sets from the separate queries. You can access them individually via data.query.results.results[n] where n is 0, 1 or 2 (corresponding with your three queries).

To loop over the results from the second query (offset 1 in the results array) you could do:

$.each(data.query.results.results[1].row, function (i, item) { … });

It may (or might not) be useful to use two $.each loops to loop over all of the rows from all of the results.

$.each(data.query.results.results, function (i, results) {
    $.each(results.row, function (i, item) {
         // do something
    });
});

Here is an adaptation of your example code, altered to build three lists — http://jsfiddle.net/XfBsj/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文