logologo
Get Started
Tutorials
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Get Started
Tutorials
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Importing Modules
Rendering in Container

Global Variables

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Next PageRunJS Overview

#RunJS Overview

RunJS is the JavaScript execution environment used in NocoBase for scenarios such as JS Blocks, JS Fields, and JS Actions. Code runs in a restricted sandbox, providing safe access to the ctx (Context API) and includes the following capabilities:

  • Top-level await
  • Importing external modules
  • Rendering within containers
  • Global variables

#Top-level await

RunJS supports top-level await, eliminating the need to wrap code in an IIFE.

Not Recommended

async function test() {}
(async () => {
  await test();
})();

Recommended

async function test() {}
await test();

#Importing External Modules

  • Use ctx.importAsync() for ESM modules (Recommended)
  • Use ctx.requireAsync() for UMD/AMD modules

#Rendering within Containers

Use ctx.render() to render content into the current container (ctx.element). It supports the following three formats:

#Rendering JSX

ctx.render(<button>Button</button>);

#Rendering DOM Nodes

const div = document.createElement('div');
div.innerHTML = 'Hello World';

ctx.render(div);

#Rendering HTML Strings

ctx.render('<h1>Hello World</h1>');

#Global Variables

  • window
  • document
  • navigator
  • ctx