Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map array of objects? #200

Open
alex-w0 opened this issue Aug 5, 2020 · 1 comment
Open

Map array of objects? #200

alex-w0 opened this issue Aug 5, 2020 · 1 comment

Comments

@alex-w0
Copy link

alex-w0 commented Aug 5, 2020

Unfortunately I can't find the answer I'm looking for in the documentation. Is there a way how I can map an array of objects like the example below? What must the scheme look like?

const object = {
  persons: [
    {
        id: 1
        name: "User 1"
    },
    {
        id: 2
        name: "User 2"
    }
 ],
 data: {
     authors: [
        {
            id: 1
            name: "User 1"
        },
        {
            id: 2
            name: "User 2"
        }
    ],
 }
};

const schema = {

};

morphism(schema, object);
@alex-w0
Copy link
Author

alex-w0 commented Aug 5, 2020

I've solved it now with the following:

persons: (iteration) => {
    return morphism(
      {
        personsId: 'id',
        personsName: 'name'
      },
      iteration.persons
    );
  },

Can you confirm that this is the official way to do this? I think there should be an example of this in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant