vendredi 26 janvier 2018

React - creating checkboxes based on data from object

I have a problem with implementing one of my ideas. Basically I want to create (in React) small app that:

1) Takes data from object, for example:

const obj = {
    person1: {
        name: 'Jessica',
        age: 25
    },
    person2: {
        name: 'Kate',
        age: 27
    },
    person3: {
        name: 'Lisa',
        age: 29
    }
};

But count of the attributes can be different than 3 (solution should be flexible).

2) Creates checkboxes with labels (names from the obj).

3) Has 2 buttons: one to check all of the checkboxes and second to deselect them.

4) Shows age when one (or more) of the users are selected, hides when not.

Seems like a simple thing to do, but I can't do it. First problem that I've encountered is how to iterate through object when creating checkboxes. forEach or map don't work. Any tips will be appreciated! Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire