- Goal: To access a nested legacy list view's value.
- Details: I have a simple app that lets people create questions and answers for a test. The app has a Number Input
NumOfQuestions
that lets you determine how many questions you're creating for this quiz. It can be any number but a minimum of 1. I have a listview (legacy) component where the number of items is determined by{{ NumOfQuestions.value }}
So when the user increments this, more list view items for the question are generated.
Next within the questions, the user can specify how many answer options there are for a given question, a question can have 2 or more answerOption
's set through the NumOfAnswers.value
. I take these and assemble into a JSON object in my query SubmitQuiz
It looks something like this
{{
Array.from({ length: NumOfQuestions.value }, (v, i) => i).map(val => {
const answerId = correctAnswerSelect[val].value;
const numOfAnswers = NumOfAnswers[val].value;
// this works up here answerOption[0][1].value
const data = {
"points": 10,
"questionId": 0,
"questionText": "",
"answerOptions": [],
"answerOptionsImages": [],
}
data.points = points[val].value;
data.questionId = val;
data.questionText = questionText[val].value;
data.answerOptions = Array.from({length: numOfAnswers}, (v, i) => i).map(NumOfAnswersVal => {
// this does not work in here answerOption[val][NumOfAnswersVal].value
// it should evaluate to answerOption[0][1].value for example
// It says val does not exist.
// The below value here fails to return the correct response. It only returns the values of answerOption[0]'th index because thats for some reason "in context" whatever that means??
return answerOption[NumOfAnswersVal].value;
}).filter(answerText => answerText)
data.answerOptionsImages = Array.from({length: numOfAnswers}, (v, i) => i).map(NumOfAnswersVal => {
return {
id: NumOfAnswersVal.toString(),
// Same issue here
url: answerOptionImage[NumOfAnswersVal].value,
answerId: NumOfAnswersVal.toString(),
}
}).filter(answerOptionImage => answerOptionImage.url)
if (answerId) {
data.answerId = answerId.toString();
}
if (data.questionText) {
return data;
}
}).filter( question => question )
}}
- Screenshots:
As you can see from the screenshot and copied below, the answerOptions are always the FIRST set of options for some reason. I cant index on map/loop to get the second set of answerOptions.
[
{"points":10,"questionId":0,"questionText":"test1","answerOptions":["a","1"],"answerOptionsImages":[{"id":"0","url":"6","answerId":"0"},{"id":"1","url":"4","answerId":"1"}]},
{"points":10,"questionId":1,"questionText":"test2","answerOptions":["a","1"],"answerOptionsImages":[{"id":"0","url":"6","answerId":"0"},{"id":"1","url":"4","answerId":"1"}]}
]
I looked and referenced and tried: