0

contanier.js

...

    getData = () => {
      const originData = this.props.results;
      const data = [
        { id: "test2",  name: "test2", gender: "male", age: 2, birth_date : 2020-09-01 },
        { id: "test3", name: "test3", gender: "other", age:3, birth_date : 2020-09-02 },
      ];
      this.setState({ data, filteredData: data });
    };

Code i want

getData = () => {
  const originData = this.props.results;
  const data = [ 
                { origindata }
  ];
  this.setState({ data, filteredData: data });
};

Currently, the id, name, age, gender, and birth_data are stored in'results'.

I defined'results' as 'origindata'.

I want to put id, name, gender, age, and birth_data from 'origindata' into const data.

But I can't figure out how to put it.

Anyone can tell me? Thank you in advance.

I'll provide more code if you like.

And if the title of the post is strange, let me know what to use as the title.

4
  • Could you show me a originData? how's look like? you can console.log it? Commented Sep 7, 2020 at 10:26
  • I uploaded a picture! Commented Sep 7, 2020 at 10:34
  • Do you want data format like sample data: const data = [ { id: "test2", name: "test2", gender: "male", age: 2, birth_date : 2020-09-01 }, { id: "test3", name: "test3", gender: "other", age:3, birth_date : 2020-09-02 }, ]; Commented Sep 7, 2020 at 10:38
  • Yes, I want it! Commented Sep 7, 2020 at 10:40

1 Answer 1

1

You can try with sample.You can custom filed you need like id and name.

 const data = originData.map(datum => ({...datum, id: datum.pid, name: datum.pid}));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.