规范化测验数据的问题

时间:2017-03-25 03:47:37

标签: javascript normalizr

回复格式:

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保持不变,我不知道我是否遗漏了什么。

1 个答案:

答案 0 :(得分:1)

您好像正在使用normalizr v2.x.仅在v3.0.0中添加了普通数组语法[ hint ]。在v2.x中,您需要使用arrayOf(hint)