以下のように入力してください。
// Text/Instructions
this.options.items.push({
"type": "text",
"title": "調査",
"content": "以下の質問項目をよく読み,あなたに当てはまる選択肢をすべて選んでください。"
})
// Check all that apply
const items = [
'飼っているのは?',
'写真集を持っているのは?',
'大好きなのは?',
'見たことがあるのは?'
];
for(let i = 0; i < items.length; i++){
itemNO = i + 1;
this.options.items.push({
"required": false,
"type": "checkbox",
"options": [
{
"label": "犬",
"coding": "1"
},
{
"label": "猫",
"coding": "2"
},
{
"label": "鳥",
"coding": "3"
},
{
"label": "兎",
"coding": "4"
},
{
"label": "亀",
"coding": "5"
}
],
"label": itemNO +". "+ items[i],
"name": "Q"+itemNO,
"shuffle": false
})
}
質問の順番をランダムにした場合でもデータでは,質問と番号の対応が変わらないようにします。
以下のようにオブジェクト(連想配列)として質問と番号を格納します。
後で使用する場合は,「itemsArray[i].label」や「itemsArray[i].name」で指定します。
// Text/Instructions
this.options.items.push({
"type": "text",
"title": "調査",
"content": "以下の質問項目をよく読み,あなたに当てはまる選択肢をすべて選んでください。"
})
// Check all that apply
const items = [
'飼っているのは?',
'写真集を持っているのは?',
'大好きなのは?',
'見たことがあるのは?'
];
//各項目と尺度名を配列に格納
var itemsArray = [];
var itemNO;
for(let i = 0; i < items.length; i++){
itemNO = i + 1;
itemsArray.push(
{
"label": items[i],
"name": "Q"+itemNO
}
)
}
連想配列の順番をシャッフルする場合は,「this.random.shuffle」を使います。
//ランダム順にする場合に並び替え
itemsArray = this.random.shuffle(itemsArray)
以下のように,「for文」の中で連想配列の値を表示します。