Subscribe to context events (such as field value changes, property changes, resource refreshes, etc.) in RunJS. Events are mapped to custom DOM events on ctx.element or internal event bus events of ctx.resource based on their type.
| Scenario | Description |
|---|---|
| JSField / JSEditableField | Listen for field value changes from external sources (forms, linkages, etc.) to synchronously update the UI, achieving two-way binding. |
| JSBlock / JSItem / JSColumn | Listen for custom events on the container to respond to data or state changes. |
| resource related | Listen for resource lifecycle events such as refresh or save to execute logic after data updates. |
| Event Name | Description | Event Source |
|---|---|---|
js-field:value-change | Field value modified externally (e.g., form linkage, default value update) | CustomEvent on ctx.element, where ev.detail is the new value |
resource:refresh | Resource data has been refreshed | ctx.resource event bus |
resource:saved | Resource saving completed | ctx.resource event bus |
Event mapping rules: Events prefixed with
resource:go throughctx.resource.on, while others typically go through DOM events onctx.element(if it exists).
ctx.on should be removed at the appropriate time via ctx.off to avoid memory leaks or duplicate triggers.ctx.off is typically called within the cleanup function of useEffect.ctx.off may not exist; it is recommended to use optional chaining: ctx.off?.('eventName', handler).ctx.on(eventName, handler) should have a corresponding ctx.off(eventName, handler), and the handler reference passed must be identical.on/off methodsjs-field:value-change)