Remove or add four elements with for-each in a list?

Inside a screen I have a list that takes in a web block. This web block is going to present one question and four answers. I managed to present each question in the block from the database.

My problem is I want to present the four first questions in the first block, and then the next four in the next block and so on. As for now all of them are being presented. 

I'm guessing I have to use the for-each to iterate over the list of questions, and add them or remove them to another list. I'm not 100% sure how to only iterate over 4 and then remove/add them. Or if it's possible to match or check the question.Id to match the foreign key in answers Entity, each of the four answers have the same foreign key to their respective Question. Maybe structure? If so how?

Any visual example would help a lot! :D


Do you need to retrieve the next 4 questions from the server or do you already have these in a List available?

For the server I would create a Server Action that would retrieve the questions and select those based on the new Index you supply as an Input (indicates the start of the next batch of questions).

For the filter I would create an action that would select the next 4 questions from the List. 

You can do select the correct records via directly accessing the records with the following statement: <variablename>.List[<indexnumber>].<record>
Don't forget to check if the Indexnumber is greater then the number of records available otherwise you will run into errors.

I hope this is clear enough. If not I can create an example when I got some time left.

Greetings,

Vincent

Vincent Koning wrote:

Do you need to retrieve the next 4 questions from the server or do you already have these in a List available?

For the server I would create a Server Action that would retrieve the questions and select those based on the new Index you supply as an Input (indicates the start of the next batch of questions).

For the filter I would create an action that would select the next 4 questions from the List. 

You can do select the correct records via directly accessing the records with the following statement: <variablename>.List[<indexnumber>].<record>
Don't forget to check if the Indexnumber is greater then the number of records available otherwise you will run into errors.

I hope this is clear enough. If not I can create an example when I got some time left.

Greetings,

Vincent

Thank you for your answer! I read my previous post and I was a wrong in describing the issue. What I meant was to iterate over the answer list and add 4 answers to the respective question. I already managed to present the questions in a list widget, and I was thinking of adding another list underneath the question, but that only displays four answers corresponding the question.

I'm creating a multiple choice test/exam for other people to test their knowledge by adding their own questions and four answers with a True boolean value (isCorrect) to the correct answer. The idea is that the user can practice as many times she/he wants and review their progress later.

 As for now my list variable that was going to hold the answers is empty, and I'm thinking of:
adding four answers to list variable -> present them on screen -> remove them, repeat until we have reach last one.


Regard.
Felipe

Solution

Hi Felipe,

Please have a look in below snapshot and OML.

Hope this will helps for you.

Regards,

Vipasha

Solution

Hi Felipe,

Typically, you would pass a QuestionId to the Web Block, and have the Web Block query the question + answers (I would assume the answer Entity has a QuestionId).

If you really want to query everything on forehand, you could pass the entire answer List to the Web Block, and use a ListFilter to filter out only those with the matching QuestionId.

Vipasha Sharma wrote:

Hi Felipe,

Please have a look in below snapshot and OML.

Hope this will helps for you.

Regards,

Vipasha

 

Thank you so much for your example! It gave a clear overview of what I needed.
The only issue I got was that I couldn't get the radio-button to be other than radio-group, and then a list of buttons appears. Don't know if it has something to do with app version I'm working on, as I'm building a reactive app?
So I used checkbox instead, but I can't use NullIdentifier(), and if I set them to false all of them will get triggered at the same time. 

Hi Felipe, 

You can proceed using check boxes, bind them with the variable and while storing the values for the respective question you have to consider the questionid as well.

Hope this will works for you

Regards,

Vipasha

Hi Felipe, 

Glad to help you,

Happy coding!!!!!!

Regards,

Vipasha