I met some strange bug during work on the one of the features for my app. I'll try explain my case in details:
I have continuously updating list of items. Update mechanism based on Rx. For the new feature I need to send some based on specified criteria and user choice.
So, when user clicks a button, ActionSheetController
is shown with some options and items are filtered based on chosen criteria and checkboxes should appear near these items.
During beginning checkboxes were visible and I used primitive array of booleans to select items what I needed. Then I used array object with two booleans, one for checkbox visibility, other for its value. And here some strange magic begins. For some reason effect one array item affected others.
export class TodayJobsPage {
//
//
//
//debug
debugCheckBoxList: Array<{isShown: boolean, value: boolean}> = [];
ionViewDidLoad() {
console.log('ionViewDidLoad TodayJobsPage');
this.jobsManager.normalUpdates.subscribe((res) => {
console.log(this.TAG + 'subscribe length ' + res.length);
this.jobsTodayList = res;
if (this.debugCheckBoxList === 0) {
this.debugCheckBoxList = new Array(res.length);
this.debugCheckBoxList.fill({value: false, isShown: false});
}
});
}
private selectJobs(status: string) {
console.log(this.TAG + 'changeAll tapped with status ' + status);
console.log(this.TAG + 'debugCheckBoxList before: ' + JSON.stringify(this.debugCheckBoxList));
this.debugCheckBoxList[2].isShown = true;
console.log(this.TAG + 'debugCheckBoxList after: ' + JSON.stringify(this.debugCheckBoxList));
}
Console:
"TodayJobsPage: changeAll tapped with status 01"
"TodayJobsPage: debugCheckBoxList before: [{"value":false,"isShown":false},{"value":false,"isShown":false},{"value":false,"isShown":false},{"value":false,"isShown":false},{"value":false,"isShown":false},{"value":false,"isShown":false}]",
"TodayJobsPage: debugCheckBoxList after: [{"value":false,"isShown":true},{"value":false,"isShown":true},{"value":false,"isShown":true},{"value":false,"isShown":true},{"value":false,"isShown":true},{"value":false,"isShown":true}]"
I'll appreciate any help or hint.
Aucun commentaire:
Enregistrer un commentaire