ctx.initResource()
Initializes the resource for the current context. If ctx.resource does not already exist, it creates one of the specified type and binds it to the context; if it already exists, it is used directly. Afterward, it can be accessed via ctx.resource.
Use Cases
Generally used in JSBlock (independent block) scenarios. Most blocks, popups, and other components have ctx.resource pre-bound and do not require manual calls. JSBlock has no resource by default, so you must call ctx.initResource(type) before loading data via ctx.resource.
Type Definition
Returns: The resource instance in the current context (i.e., ctx.resource).
Difference from ctx.makeResource()
Examples
List Data (MultiRecordResource)
Single Record (SingleRecordResource)
Specify Data Source
Notes
- In most block scenarios (Forms, Tables, Details, etc.) and popups,
ctx.resourceis already pre-bound by the runtime environment, so callingctx.initResourceis unnecessary. - Manual initialization is only required in contexts like JSBlock where there is no default resource.
- After initialization, you must call
setResourceName(name)to specify the collection, and then callrefresh()to load the data.
Related
- ctx.resource — The resource instance in the current context
- ctx.makeResource() — Creates a new resource instance without binding it to
ctx.resource - MultiRecordResource — Multiple records/List
- SingleRecordResource — Single record
- APIResource — General API resource
- SQLResource — SQL query resource

