0
I have a list of tasks stored in an object items
, I want to parse this list so that, anything with status open is stored in the variable openTasks
and everything with status completed is storing in completedTasks
.
I even scribbled something but it didn’t work out. Look:
export class AllTasksPage {
openTasks;
completedTasks;
items = [
{'title': 'Entregar relatório', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Fazer compras', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Concluir trabalho da faculdade', 'note': '', 'image': '', 'status': 'concluida'},
{'title': 'Ligar para cliente', 'note': '', 'image': '', 'status': 'concluida'},
{'title': 'Revisar trabalho', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Falar com chefe', 'note': '', 'image': '', 'status': 'concluida'},
{'title': 'Estudar apra prova', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Buscar roupa na lavanderia', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Limpar a casa', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Estudar para apresentação', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Assistir filme xpto', 'note': '', 'image': '', 'status': 'aberta'},
{'title': 'Colocar a roupa para lavar', 'note': '', 'image': '', 'status': 'aberta'}
];
constructor(public navCtrl: NavController, public alertCtrl: AlertController) {
for (let item of this.items) {
if (item.status == 'aberta') {
this.openTasks.concat(item);
}
}
}
In short: I want openTasks
and comletedTasks
have the same existing structure in items
, however, the data will change based on the status of the tasks.
You can use the
filter
to pass data from one array to another, the first will only be with theopen
and the other with thecompleted
– Costamilam