标准化测验数据的问题

Issue in normalizing quiz data

响应格式:

const fakeDatabase = {
  quizzes: [{
    id: v4(),
    title: 'Get started',
    text: 'hey',
    completed: true,
    hints: [{
      id: 1,
      text: 'Hint 1'
    }, {
      id: 2,
      text: 'Hint 2'
    }]
  }, {
    id: v4(),
    title: 'What are you waiting for?',
    text: 'ho',
    completed: true,
    hints: [{
      id: 3,
      text: 'Hint 3'
    }, {
      id: 4,
      text: 'Hint 4'
    }]
  }, {
    id: v4(),
    title: 'Remember! create more than you consume',
    text: 'let’s go',
    completed: false,
    hints: [{
      id: 5,
      text: 'Hint 5'
    }, {
      id: 6,
      text: 'Hint 6'
    }]
  }],
};

我有以下架构:

import { Schema, arrayOf } from 'normalizr';

export const hint = new Schema('hints');

export const quiz = new Schema('quizzes', {
  hints: [ hint ]
});

export const arrayOfQuiz = arrayOf(quiz);

但是在规范化之后我得到以下响应:

normalize(response, schema.arrayOfQuiz)

因此,基本上我的测验已正确标准化,但 hints 保持原样,我不知道我是否遗漏了什么。

您似乎在使用 normalizr v2.x。仅在 v3.0.0 中添加了纯数组语法 [ hint ]。在v2.x中,你需要使用arrayOf(hint).