Skip to content

How to pass information to child items with node-object-mapper #98

Description

@MateusArenas

I really like this JavaScript library, and I would love for it to support what I need for a project I'm working on. Could you help me with this, @matmar10 , @wankdanker , @irnc , @weshardee , @kevinvn1709 ?

I would like to dynamically pass a value to the child items below.

{
  "pedido": {
    "volumes": [
      {
        "itens": [
          {
            "etiqueta": "abc",
            "cod_item": 1
          },
          {
            // The value didn't appear here...
            "cod_item": 5
          },
          {
            // The value didn't appear here...
            "cod_item": 6
          }
        ]
      },
      {
        "itens": [
          {
            "etiqueta": "zpl",
            "cod_item": 3
          }
        ]
      }
    ]
  }
}

var mapping = {
  "pedido.volumes[].registro": [
    "pedido.volumes[].itens[].etiqueta"
  ],
  "pedido.volumes[].itens[].codigo": [
    "pedido.volumes[].itens[].cod_item"
  ]
};

const originalData = { 
  pedido: {
    volumes: [
      {
        registro: 'abc',
        itens: [
          { codigo: 1 },
          { codigo: 5 },
          { codigo: 6 }
        ]
      },
      {
        registro: 'zpl',
        itens: [
          { codigo: 3 }
        ]
      }
    ]
  }
};

const mappedData = objectMapper(originalData, mapping);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions