logologo
시작
가이드
개발
플러그인
API
홈
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
시작
가이드
개발
플러그인
API
홈
logologo
RunJS 개요
모듈 가져오기
컨테이너 내 렌더링

전역 변수

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.blockModel
Next Pagectx.collectionField
AI 번역 알림

이 문서는 AI에 의해 번역되었습니다. 정확한 정보는 영어 버전을 참조하세요.

#ctx.collection

현재 RunJS 실행 컨텍스트와 연결된 컬렉션(Collection) 인스턴스로, 컬렉션의 메타데이터, 필드 정의 및 기본 키(Primary Key) 등의 설정에 접근하는 데 사용됩니다. 일반적으로 ctx.blockModel.collection 또는 ctx.collectionField?.collection에서 가져옵니다.

#적용 시나리오

시나리오설명
JSBlock블록에 바인딩된 컬렉션입니다. name, getFields, filterTargetKey 등에 접근할 수 있습니다.
JSField / JSItem / JSColumn현재 필드가 속한 컬렉션(또는 상위 블록 컬렉션)입니다. 필드 목록, 기본 키 등을 가져오는 데 사용됩니다.
테이블 열 / 상세 블록컬렉션 구조에 따라 렌더링하거나, 팝업을 열 때 filterByTk 등을 전달할 때 사용됩니다.

주의: ctx.collection은 데이터 블록, 폼 블록, 테이블 블록 등 컬렉션이 바인딩된 시나리오에서 사용할 수 있습니다. 컬렉션이 바인딩되지 않은 독립적인 JSBlock의 경우 null일 수 있으므로, 사용 전 null 체크를 권장합니다.

#타입 정의

collection: Collection | null | undefined;

#주요 속성

속성타입설명
namestring컬렉션 이름 (예: users, orders)
titlestring컬렉션 제목 (다국어 포함)
filterTargetKeystring | string[]기본 키 필드명, filterByTk 및 getFilterByTK에 사용됨
dataSourceKeystring데이터 소스 키 (예: main)
dataSourceDataSource소속된 데이터 소스 인스턴스
templatestring컬렉션 템플릿 (예: general, file, tree)
titleableFieldsCollectionField[]제목으로 표시 가능한 필드 목록
titleCollectionFieldCollectionField제목 필드 인스턴스

#주요 메서드

메서드설명
getFields(): CollectionField[]모든 필드 가져오기 (상속 포함)
getField(name: string): CollectionField | undefined필드 이름으로 단일 필드 가져오기
getFieldByPath(path: string): CollectionField | undefined경로로 필드 가져오기 (관계 지원, 예: user.name)
getAssociationFields(types?): CollectionField[]관계 필드 가져오기, types는 ['one'], ['many'] 등이 될 수 있음
getFilterByTK(record): any레코드에서 기본 키 값을 추출하여 API의 filterByTk에 사용

#ctx.collectionField, ctx.blockModel과의 관계

요구사항권장 용법
현재 컨텍스트와 연결된 컬렉션ctx.collection (ctx.blockModel?.collection 또는 ctx.collectionField?.collection과 동일)
현재 필드의 컬렉션 정의ctx.collectionField?.collection (필드가 속한 컬렉션)
관계 대상 컬렉션ctx.collectionField?.targetCollection (관계 필드의 대상 컬렉션)

하위 테이블 등의 시나리오에서 ctx.collection은 관계 대상 컬렉션일 수 있습니다. 일반적인 폼/테이블에서는 보통 블록에 바인딩된 컬렉션입니다.

#예시

#기본 키 가져오기 및 팝업 열기

const primaryKey = ctx.collection?.filterTargetKey ?? 'id';
await ctx.openView(popupUid, {
  mode: 'dialog',
  params: {
    filterByTk: ctx.record?.[primaryKey],
    record: ctx.record,
  },
});

#필드를 순회하며 유효성 검사 또는 연동 수행

const fields = ctx.collection?.getFields() ?? [];
const requiredFields = fields.filter((f) => f.options?.required);
for (const f of requiredFields) {
  const v = ctx.form?.getFieldValue(f.name);
  if (v == null || v === '') {
    ctx.message.warning(`${f.title}은(는) 필수 항목입니다`);
    return;
  }
}

#관계 필드 가져오기

const oneToMany = ctx.collection?.getAssociationFields(['many']) ?? [];
// 하위 테이블, 관계 리소스 등을 구성하는 데 사용

#주의사항

  • filterTargetKey는 컬렉션의 기본 키 필드명입니다. 일부 컬렉션은 string[] 형태의 복합 키를 가질 수 있으며, 설정되지 않은 경우 보통 'id'를 기본값으로 사용합니다.
  • 하위 테이블, 관계 필드 등의 시나리오에서 ctx.collection은 관계 대상 컬렉션을 가리킬 수 있으며, 이는 ctx.blockModel.collection과 다를 수 있습니다.
  • getFields()는 상속된 컬렉션의 필드를 병합하며, 자신의 필드가 동일한 이름의 상속된 필드를 덮어씁니다.

#관련 정보

  • ctx.collectionField: 현재 필드의 컬렉션 필드 정의
  • ctx.blockModel: 현재 JS를 포함하는 부모 블록, collection 포함
  • ctx.model: 현재 모델, collection을 포함할 수 있음