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
Previous Pagectx.dataSourceManager
Next Pagectx.exit()

#ctx.element

Points to the sandbox DOM container as an ElementProxy instance.

#Type definition

element: ElementProxy

#Notes

ctx.element is an ElementProxy for the sandbox container. For safety, do not call ctx.element APIs directly (e.g. innerHTML, appendChild, querySelector).

NocoBase JS blocks provide an element proxy that only exposes safe attributes and methods.

#Security requirements

Do not use ctx.element APIs directly. All DOM operations must go through ctx.render().

#Incorrect usage

// Not allowed: direct ctx.element access
ctx.element.innerHTML = '<div>Content</div>';
ctx.element.appendChild(node);
ctx.element.querySelector('.class');

#Correct usage: use ctx.render()

All rendering should go through ctx.render():

// Render React components
const { Button, Card } = ctx.libs.antd;

ctx.render(
  <Card title={ctx.t('Welcome')}>
    <Button type="primary">Click</Button>
  </Card>
);
// Render HTML string
ctx.render('<div style="padding:16px;">' + ctx.t('Content') + '</div>');
// Render DOM node
const div = document.createElement('div');
div.textContent = ctx.t('Hello');
ctx.render(div);

#Why ctx.render() is required

Benefits of ctx.render():

  • Security: centralized safety checks
  • React support: full React and JSX support
  • Context inheritance: app context is inherited automatically
  • Lifecycle: better component lifecycle management
  • Conflict handling: manages React root creation/unmounting

#Notes

  • ctx.element is only used as the internal container for ctx.render()
  • Do not access or modify ctx.element properties directly
  • All rendering must go through ctx.render()