Skip to content

Commit 55b253f

Browse files
authored
Fix: useranswer save/restore _index awareness (fixes #489) (#490)
1 parent e218075 commit 55b253f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

js/models/itemsComponentModel.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ export default class ItemsComponentModel extends ComponentModel {
2424
restoreUserAnswers() {
2525
const booleanArray = this.get('_userAnswer');
2626
if (!booleanArray) return;
27-
this.getChildren().forEach((child, index) => child.set('_isVisited', booleanArray[index]));
27+
this.getChildren().forEach(child => child.set('_isVisited', booleanArray[child.get('_index')]));
2828
}
2929

30-
storeUserAnswer() {
31-
const booleanArray = this.getChildren().map(child => child.get('_isVisited'));
30+
storeUserAnswer() {
31+
const items = this.getChildren().slice(0);
32+
items.sort((a, b) => a.get('_index') - b.get('_index'));
33+
const booleanArray = items.map(child => child.get('_isVisited'));
3234
this.set('_userAnswer', booleanArray);
3335
}
3436

0 commit comments

Comments
 (0)