morphism icon indicating copy to clipboard operation
morphism copied to clipboard

Map array of objects?

Open alex-w0 opened this issue 3 years ago • 1 comments

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 avatar Aug 05 '20 16:08 alex-w0

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.

alex-w0 avatar Aug 05 '20 17:08 alex-w0