[英]Use data from Quandl API to show in Appsmith table widget
I am building a web-app and want to connect data from Quandl through its JSON API.我正在构建一个网络应用程序,并希望通过其 JSON API 连接来自 Quandl 的数据。 However, the JSON I get from quandl has the column names separate from the data itself, check below:
但是,我从 quandl 获得的 JSON 的列名与数据本身分开,请查看以下内容:
{
"datatable": {
"data": [
[
"AAPL",
"MRY",
"2020-12-31",
"2020-09-26",
"2020-09-26",
"2021-07-28",
-406000000,
323888000000,
325562500000
]
],
]
],
"columns": [
{
"name": "ticker",
"type": "String"
},
{
"name": "dimension",
"type": "String"
},
{
"name": "calendardate",
"type": "Date"
},
{
"name": "datekey",
"type": "Date"
},
{
"name": "reportperiod",
"type": "Date"
},
{
"name": "lastupdated",
"type": "Date"
},
{
"name": "accoci",
"type": "Integer"
},
{
"name": "assets",
"type": "Integer"
},
{
"name": "assetsavg",
"type": "Integer"
}
]
},
"meta": {
"next_cursor_id": null
}
}
When I use this data in Appsmith, it can not infer the column names.当我在 Appsmith 中使用此数据时,它无法推断列名。 Is there a simple javascript code to combine the column names with the data?
是否有一个简单的 javascript 代码来将列名与数据结合起来? Thank you!
谢谢!
This is possible with a simple JS snippet, Now my code written is not that great but will work in this case (Can be optimised)这可以通过一个简单的 JS 片段实现,现在我编写的代码不是那么好,但在这种情况下可以工作(可以优化)
{{
function() {
let tableData = [];
_.map(_d.datatable.data, (v, i) => {
let set = {}
_.map(v, (x, k) => {
var obj = {[_d.datatable.columns[k].name]: x}
set = {...set, ...obj}
})
tableData.push(set)
})
}()
}}
In the above snippet _d
is the data which you receive, We map the array value index with the given column index and create a new object out of it, Also since this is a multiline JS code, In Appsmith we need to write this inside an IIFE like above.在上面的代码片段中,
_d
是您收到的数据,我们将数组值索引映射到给定的列索引并从中创建一个新对象,而且由于这是多行 JS 代码,在 Appsmith 中我们需要将其写在一个像上面的 IIFE。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.