문항 객체
Question object는 safe survey logic에서 model metadata와 live answer state를 노출합니다. Metadata는 read-only입니다. Mutation method는 <run-code>처럼 명시적으로 mutation을 허용하는 runtime flow에서만 사용할 수 있습니다.
Question object는 두 형태로 사용할 수 있습니다.
Q1,AGE,SEGMENT처럼 다른 문항 또는 auto-punch answer를 가리키는 named reference.- Question-local logic에서 현재 평가 중인 문항을 가리키는
$curr.
핵심 metadata
Q1.name
Q1.type
Q1.description
Q1.comment
Q1.required
Q1.hidden
Q1.pageIndex
Q1.displayStyle
Q1.min
Q1.max
Q1.step
Q1.order
Answer reader
Q1.value
Q1.answer
Q1.values
Q1.count
Q1.sum
Q1.isAnswered
Q1.isBlank
Q1.val()
Q1.first()
Q1.last()
Q1.rank(1)
Q1.has(1)
Q1.includes(1)
Q1.equals(1)
Q1.isin([1, 2, 3])
Q1.all([1, 2])
Q1.toArray()
Q1.toJSON()
value와 answer는 normalized current value를 반환합니다. values는 choice/ranking answer에서 비교 가능한 array-like list를 반환합니다.
Option과 attribute
Q1.o1
Q1.om2
Q1.options.o1.label
Q1.options.o98.isOpenEnded
Q1.option(1).selected
Q1.attr1.value
Q1.attrs.attr1.options.o2.selected
Q1.attr(1).has(2)
Positive option alias는 o{code}입니다. Negative option alias는 om{abs(code)}입니다. Attribute alias는 attr{code} 또는 attrm{abs(code)}입니다.
$curr
$curr는 question-local logic에서 current question object입니다. Option, attribute, group, validation, run-code block이 현재 문항 안에서 재사용 가능해야 할 때 사용합니다.
<question type="multi" name="BRAND">
<run-code>
if ($curr.o1 && $curr.o2) {
setAnswer("BRAND_SEGMENT", "dual");
}
</run-code>
<options>
<option value="1">Brand A</option>
<option value="2">Brand B</option>
<option value="3" if="$curr.o1">Shown after Brand A</option>
</options>
</question>
Top-level redirect, quota, screen-out, jump, share-list logic에서는 $curr를 사용하지 않습니다. 그 위치에서는 named question reference를 사용하세요.
Run-code mutation method
Q1.setAnswer(1);
Q1.clearAnswer();
Q_MULTI.options.o2.toggle();
Q_ATTR.attrs.attr1.options.o2.select();
Mutation method는 type-aware이며 compact if, <condition>, <validation>에서는 의도적으로 사용할 수 없습니다. 해당 read-only 위치에서는 Q1.val() 또는 Q1.has(1) 같은 reader를 사용합니다.
$quota helper
$quota는 frozen quota snapshot namespace입니다. 각 property name은 quota sheet/source id입니다. 없는 sheet는 undefined, 없는 cell은 null을 반환합니다.
$quota.gender_quota.cells
$quota.gender_quota.get("male_18_34")
$quota.gender_quota.getPriorityCells()
$quota.gender_quota.getPriorityCells(2, "ratio")
$quota.gender_quota.getAssignmentCells()
| Member/method | 반환값 | 메모 |
|---|---|---|
$quota.{sheet}.cells | Array<{ id, label }> | Trusted quota definition의 authored cell id와 label입니다. |
$quota.{sheet}.get(cellId) | { label, limit, complete, quotafull } 또는 null | 현재 persisted snapshot 기준 count입니다. complete는 complete sample count, quotafull은 quota-full count입니다. |
$quota.{sheet}.getPriorityCells(count = 1, type = "count") | Array<string> | 실제 quota assignment와 같은 count/ratio priority algorithm으로 부족한 eligible cell id를 반환합니다. count가 1이어도 항상 array를 반환합니다. 동률은 랜덤 선택될 수 있습니다. |
$quota.{sheet}.getAssignmentCells() | Array<string> | 코드 실행 시점의 현재 응답자가 해당 quota sheet에서 assigned/counted 된 cell id입니다. 관련 <quota> checkpoint 전에는 보통 빈 배열입니다. |
이 helper는 의도적으로 DB-free입니다. Authored JavaScript는 Survey Link, server persistence, Run generate가 주입한 runtime snapshot만 읽고, quota row를 직접 fetch하거나 server-side quota authority를 우회할 수 없습니다.
<quota source="concept_quota" />
<question type="single" name="HQ_CONCEPT" hidden>
<run-code>
const ids = $quota.concept_quota.getAssignmentCells();
const first = ids.at(0);
if (first) {
setAnswer("HQ_CONCEPT", String(first).replace("r", ""));
}
</run-code>
<options>
<option value="1">Concept A</option>
<option value="2">Concept B</option>
</options>
</question>
Time과 params helper
$now는 evaluation 시점의 Luxon DateTime입니다. $params는 runtime이 제공하는 Survey Link URL params object입니다.
$now.toISODate()
$params.source
$params.campaign
작성된 date answer를 파싱할 때는 Luxon.DateTime.fromISO(QDATE.value)를 사용합니다.