【问题标题】:How do I move child objects of 'entities' up to the top level and rename 'results' object in normalizr?如何将“实体”的子对象移动到顶层并在 normalizr 中重命名“结果”对象?
【发布时间】:2017-11-24 21:22:15
【问题描述】:

现在当我规范化这个数组时:

[
   {
      "teamName":"abc",
      "description":"",
      "id":"123"
   },
   {
      "teamName":"def",
      "description":"",
      "id":"456"
   }
]

Normalizr 输出:

{
   "result":[
      "123",
      "456"
   ],
   "entities":{
      "teams":{
         "123":{
            "teamName":"abc",
            "description":"",
            "id":"123"
         },
         "456":{
            "teamName":"def",
            "description":"",
            "id":"456"
         }
      }
   }
}

纯粹通过修改schema,有没有办法代替输出呢?

{
   "queries":[
      "123",
      "456"
   ],
   "teams":{
      "123":{
         "teamName":"abc",
         "description":"",
         "id":"123"
      },
      "456":{
         "teamName":"def",
         "description":"",
         "id":"456"
      }
   }
}

我知道事后我可以很容易地做到这一点,但是有没有内置的方法来调整输出的 JSON 数据的结构?

【问题讨论】:

    标签: redux normalizr


    【解决方案1】:

    Normalizr 旨在为仅使用两个顶级键 resultsentities 的所有输出提供标准响应。没有选项可以满足您的要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 2017-02-02
      • 2011-01-10
      • 2017-01-29
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      相关资源
      最近更新 更多