同步操作将从 Gitee 极速下载/tooljet 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
id | title |
---|---|
transformations | Transformations |
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Transformations can be enabled on queries to transform the query results. ToolJet allows you to transform the query results using two programming languages:
:::caution
RunJS
.
:::Let's write a simple transformation to compute first_name
and last_name
for all the customers that we fetch in the previous step.
// write your code here
// return value will be set as data and the original data will be available as rawData
return data.map((row) => {
return {
...row,
first_name: row.name.split(' ')[0],
last_name: row.name.split(' ')[1],
};
});
The query will now look like this:
Let's use Python transformation to compute first_name
and last_name
for all the customers that we fetch in the previous step.
return list(map(lambda row: {
**row,
'first_name': row['name'].split(' ')[0],
'last_name': row['name'].split(' ')[1],
}, data))
Let's take a look at the data returned by a RESTAPI (using mock data here):
Now we will transform the returned data using Python that will append a new key in the returned data called user
and that user will have the value from the exposed global variables of ToolJet which is globals.currentUser.email
return list(map(lambda item: {**item, "user": f"{globals['currentUser']['email']}"}, data))
Now, you can click on the preview button to check the transformed data.
Click the create
button to create the query. Saved queries can be run using the run
icon near the query name. Queries run using the run button will behave just as if it was triggered by an app event like button click and thus will alter the state of the app. You can view the query results using the state inspector on the left side-bar of the app builder.
We can see that first_name
and last_name
are added to all the rows in the data
object of the query. If you need the original data of the query, it will be available in the rawData
object of the query.
In the next section, we will see how we can display this data using ToolJet's built-in widgets.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。