logologo
Get Started
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Get Started
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Import Modules
Render in Container

Globals

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 in NocoBase for JS blocks, JS fields, JS actions, and related scenarios. Code runs in a restricted sandbox, safely exposing ctx (context APIs), and provides:

  • Top-level async (Top-level await)
  • Import external modules
  • Render in container
  • Globals

#Top-level async (Top-level await)

RunJS supports top-level await, no IIFE required.

Not recommended

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

Recommended

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

#Import external modules

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

#Render in container

Use ctx.render() to render into the current container (ctx.element). Three supported forms:

#Render JSX

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

#Render DOM nodes

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

ctx.render(div);

#Render HTML strings

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

#Globals

  • window
  • document
  • navigator
  • ctx