normalize数组在第一个索引处生成一个空槽

时间:2017-11-23 14:23:08

标签: javascript json redux normalizr

我是React,Redux和normalizr的新手。我尝试使用 normalizr 规范化我提取的数据。

鉴于此JSON:

   {'teams': [
    {
        "id": 1,
        "nom": "Team1"
    },
    {
        "id": 2,
        "nom": "Team2"
    },
    {
        "id": 3,
        "nom": "Team3"
    }]}

我想将以下规范化模式应用于normalizr:

import { normalize, schema } from 'normalizr';

const teamSchema = new schema.Entity('teams');
const preloadedStateSchema = { teams: [ teamSchema ] };
const normalizedData = normalize(preloadedState, preloadedStateSchema);

我的期望:

{
    entities: {
        teams: {
            1: {
            "id": 1,
            "nom": "Team1"
            },
            2: {
                "id": 2,
                "nom": "Team2"
            },
            3: {
                "id": 3,
                "nom": "Team3"
            }
        },
    result:{
        teams: [1, 2, 3]
    }
}

我得到了什么:

{
    entities: {
        teams: {
            1: **<EMPTY SLOT>**
            2: {
                "id": 2,
                "nom": "Team2"
            },
            3: {
                "id": 3,
                "nom": "Team3"
            }
        },
    result:{
        teams: [1, 2, 3]
    }
}

这个&#34;空位&#34;来自?如何解决这个问题?

0 个答案:

没有答案