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.importAsync()
Next Pagectx.libs

#ctx.initResource()

Initialize the resource in the current context: if ctx.resource does not exist, create it with the specified type and bind it; if it already exists, reuse it. You can then access it via ctx.resource.

#Type

initResource(type: ResourceType): FlowResource;
  • type: resource type, commonly 'APIResource', 'SingleRecordResource', 'MultiRecordResource', 'SQLResource'.
  • Return: the resource instance in the current context (ctx.resource).

#Example

// Ensure ctx.resource exists; create it by type if not
ctx.initResource('MultiRecordResource');
ctx.resource.setResourceName('users');
await ctx.resource.refresh();
const rows = ctx.resource.getData();

Difference from makeResource: initResource ensures and may set ctx.resource; makeResource only creates a new instance and does not change ctx.resource.

See detailed APIs for each Resource type:

  • MultiRecordResource
  • SingleRecordResource
  • APIResource
  • SQLResource