jQuery 到 JSON API 的嵌套查询 google 个图表
jQuery nested query to JSON API with google charts
我有这个 JSON 来自 API,我想从第一个“Datos”的数据中获取“值”和“日期”。
问题是它只从每个带有 [Data[0].Date]、[Data[0].Value] 的“Datos”中获取第一个数字(代码如下)。我怎样才能分别从第一个和第二个中获取所有值。
"Datos":[
{
"Date":"2020-11-01",
"Value":100
},
{
"Date":"2020-10-01",
"Value":101
},
{
"Date":"2020-09-01",
"Value":102
},
]
"Datos":[
{
"Date":"2020-11-01",
"Value":1%
},
{
"Date":"2020-10-01",
"Value":2%
},
{
"Date":"2020-09-01",
"Value":3%
},
]
我正在使用此代码:
<script>
function drawLineChart() {
$.ajax({
url: "url",
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
var arrSales = [ [ 'Month', 'Sales Figure' ] ];
$.each(data, function (index, value) {
arrSales.push([ value.Datos[0].Date, value.Datos[0].Value ]);
});
}
})
}
</script>
谢谢!!
这应该获取 data
中第一个 Datos
的所有数据...
function drawLineChart() {
$.ajax({
url: "url",
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
var arrSales = [ [ 'Month', 'Sales Figure' ] ];
if (data.length > 0) {
$.each(data[0].Dataos, function (index, value) {
arrSales.push([ value.Date, value.Value ]);
});
}
}
})
}
我有这个 JSON 来自 API,我想从第一个“Datos”的数据中获取“值”和“日期”。
问题是它只从每个带有 [Data[0].Date]、[Data[0].Value] 的“Datos”中获取第一个数字(代码如下)。我怎样才能分别从第一个和第二个中获取所有值。
"Datos":[
{
"Date":"2020-11-01",
"Value":100
},
{
"Date":"2020-10-01",
"Value":101
},
{
"Date":"2020-09-01",
"Value":102
},
]
"Datos":[
{
"Date":"2020-11-01",
"Value":1%
},
{
"Date":"2020-10-01",
"Value":2%
},
{
"Date":"2020-09-01",
"Value":3%
},
]
我正在使用此代码:
<script>
function drawLineChart() {
$.ajax({
url: "url",
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
var arrSales = [ [ 'Month', 'Sales Figure' ] ];
$.each(data, function (index, value) {
arrSales.push([ value.Datos[0].Date, value.Datos[0].Value ]);
});
}
})
}
</script>
谢谢!!
这应该获取 data
中第一个 Datos
的所有数据...
function drawLineChart() {
$.ajax({
url: "url",
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
var arrSales = [ [ 'Month', 'Sales Figure' ] ];
if (data.length > 0) {
$.each(data[0].Dataos, function (index, value) {
arrSales.push([ value.Date, value.Value ]);
});
}
}
})
}