如何将一组平面对象标准化为其实体?

时间:2016-07-27 15:59:29

标签: normalizr

给出如下输入:

[
  {
    id: 11,
    valueId: 22,
    valueDescription: 'Some value',
    referenceId: 33,
    referenceDescription: 'Some reference',
    groupId: 44,
    groupDescription: 'Some group'
  },
  {
    id: 55,
    valueId: 66,
    valueDescription: 'Another value',
    referenceId: 77,
    referenceDescription: 'Another reference',
    groupId: 88,
    groupDescription: 'Another group'
  }
]

所需的输出:

{
  entities: {
    types: {
      "11": { id: 11, valueId: 22, referenceId: 33, groupId: 44 },
      "55": { id: 55, valueId: 66, referenceId: 77, groupId: 88 },
    },
    values: {
      "22": { id: 22, description: "Some value" },
      "66": { id: 66, description: "Another value" },
    },
    references: {
      "33": { id: 33, description: "Some reference" },
      "77": { id: 77, description: "Another reference" },
    },
    groups: {
      "44": { id: 44, description: "Some group" },
      "88": { id: 88, description: "Another group" },
    }
  },
  result: [ 11, 55 ]
}

我不确定如何为我的4种实体类型定义Schema,这些实体类型会从展平的根对象中拉出多个字段并重命名它们。我看到我可以传递的assignEntity参数我认为我将用于重命名部分,但我不确定如何定义Schema以指示一个扁平对象变为四个实体。

0 个答案:

没有答案