Picture of Matt Leathes
Re: Modifying MCQ choices
by Matt Leathes - Thursday, 9 January 2020, 3:32 PM
 

OK so first off, it may just be a copy-paste error but the sample line of code you supplied:

Adapt.findById('c-lvl01').set('_items', ''[{"text":"First","_shouldBeSelected":false,"feedback":""},{"text":"Second","_shouldBeSelected":false,"feedback":""},{"text":"Third","_shouldBeSelected":false,"feedback":""}],);

Isn't quite right in that you have quotes before the opening [ character - and a trailing comma after the closing ] character.

But even with that corrected it still might not work. Unfortunately you don't say what version of MCQ you're using - but assuming it's v3.0.0 then the _items get read into a data model (itemsQuestionModel.js) that handles a lot of the shared logic used by multiple choice questions. So you'll need to force it to 'refresh' that with the new data.

A VERY cursory bit of hacking around with this suggests that calling the setupItems method of the model looks like it might work - but that needs significantly more testing to check there's no knock-on effects. I didn't have much involvement in the work to add this new data model so I'm not as familiar with how it works as others might be.

If the MCQ you're trying to change is on the same page as the one that changes it, you're also going to need to force the component to re-render to pick up the changes as, unfortunately, changing the data model in Backbone applications doesn't automatically update the view like you'd expect if you're using to working with VueJS or React.

If you also need the learner's choice of answers to be remembered 'between sessions' (see the _shouldStoreResponses setting of the spoor extension)  - I have no idea if that would work given what you're doing!

Instead of trying to change an existing MCQ, a better option might be to have multiple instances of the MCQ - and to use the _isAvailable property to hide the ones you don't want and show the ones you do?