无法从Normalizr获取实体

时间:2019-12-10 15:05:23

标签: react-redux normalizr

我是Reactjs和Redux的新手,正在尝试使用Normalizr库对一些响应数据进行规范化。我的测试代码是:

const nodeSchema = new schema.Entity('node', {}, { idAttribute: 'nodeId' });
const nodeListSchema = new schema.Array(nodeSchema);
const data = [
    {
      "nodeId": "ping.1",
      "available": false,
      "NodeApiURL": "https://www.somewhere.com",
      "NodeType": "Static"
    },
    {
      "nodeId": "testDevice1",
      "available": false,
      "NodeApiURL": "https://www.somewhere.com",
      "NodeType": "Dynamic"
    },
    {
      "nodeId": "device",
      "available": false,
      "NodeApiURL": "https://www.somewhere.com",
      "NodeType": "Static"
    },
    {
      "nodeId": "10.0.1.5:1234",
      "availableForCommunity": true,
      "NodeApiURL": "https://www.somewhere.com",
      "NodeType": "Static"
    }
  ];
  console.log("updating available nodes: ", data);
  const { entities: { nodes }, result } = normalize(data, nodeListSchema);
  console.log("updating available entities: ", nodes);
  console.log("result: ", result);

但是,如果“ nodeId”值,结果将按预期返回列表,但是我没有返回任何实体(节点)。有人可以告诉我我错了吗?

谢谢

0 个答案:

没有答案