如何将“实体”的子对象移动到顶层并在normalizr中重命名“结果”对象?

时间:2017-06-21 19:51:09

标签: redux normalizr

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

[
   {
      "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"
         }
      }
   }
}

纯粹通过修改架构,有没有办法输出它?

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

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

1 个答案:

答案 0 :(得分:0)

Normalizr旨在为所有输出提供标准响应,只有两个顶级键resultsentities。没有选项来执行您的请求。