如何在normalizr中将另一个字段称为id?

时间:2018-12-15 19:52:33

标签: normalizr

我有这样的回复:

{
  count:2,
  todos: [ { complete: false,
        _id: '5c15338940b1893ff8e53c63',
        text: 'add todo test',
        userId: '5c0c0965f9c34b071c11a3f1',
       createdAt: '2018-12-15T17:02:01.512Z',
        updatedAt: '2018-12-15T17:02:01.512Z',},
      { complete: false,
        _id: '5c1532bdccba3c2128358764',
        text: 'add todo test',
        userId: '5c0c0965f9c34b071c11a3f1',
        createdAt: '2018-12-15T16:58:37.134Z',
        updatedAt: '2018-12-15T16:58:37.134Z', },

我正在使用猫鼬,因此我将_id作为ID,我现在具有以下架构:

const todo = new schema.Entity('todos');;
    const result = normalize(response, {
      todos: [todo],
    })

我还想列出对象ID?在我的结果中,我希望拥有:

{
  entities: {
   todos: {
     5c15338940b1893ff8e53c63: { ... },
     5c1532bdccba3c2128358764: { ... },
   },
   ids: ['5c15338940b1893ff8e53c63', '5c1532bdccba3c2128358764']
  }
}

我是normalizr的新手,很难过,我想我可以使用map添加id属性,但是感觉不对,有帮助吗?

0 个答案:

没有答案