1 Star 4 Fork 32

HuangWanddy/tooljet

forked from Gitee 极速下载/tooljet 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
custom-js.md 2.13 KB
一键复制 编辑 原始数据 按行查看 历史
idtitle
custom-jsCustom JavaScript

Custom JavaScript

You can write custom JavaScript code to interact with components and queries. To do that, you just need to create a new query and select Run JavaScript Code from the data sources dropdown.

custom js

Example: Displaying random number

  • Let's drag a button and a text widget inside a container widget.
  • Create a new query and select Run JavaScript code from dropdown.
  • Write the code in JavaScript editor and save the query:
const a = Math.floor(Math.random() * (10 - 1)) + 1;
return a;

:::tip

The return value is used as the data of the query.

:::

  • Let's edit the properties of widgets:
    • Add an event handler to the button - Select On Click event, Run Query action, and select the runjs1 query that we created. This will run the JavaScript code every time the button is clicked.
    • Edit the property of text widget - In the text field enter Random number: {{queries.runjs1.data}}. It will display the output as Random number: result from JS code
jsrandom

You can also write custom JavaScript code to get the data from External APIs and manipulate the response for graphical representation. Here's the tutorial on how we used custom JavaScript code to build an app using GitHub API.

Libraries

ToolJet allows you to internally utilize these libraries:

Name Documentation
Moment https://momentjs.com/docs/
Lodash https://lodash.com/docs/
Axios https://axios-http.com/docs/intro

:::danger

Issues with writing custom JavaScript code? Ask in our Slack community.

:::

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/wanddyh/tooljet.git
git@gitee.com:wanddyh/tooljet.git
wanddyh
tooljet
tooljet
develop

搜索帮助