小编cdn*_*n34的帖子

normalizr模式中的嵌套数组

我需要规范化这些数据,以便我有一个列表数组和另一个待办事项.

const data = [ 
  { 
    _id: '1', 
    title: 'List1', 
    todos: [
      {
         _id: "11", 
         text: "Test1"
      }
    ] 
  },
  { 
    _id: '2', 
    title: 'List2', 
    todos: [
      {
         _id: "22", 
         text: "Test2"
      }
    ] 
  } 
];
Run Code Online (Sandbox Code Playgroud)

这是我得到的:

const todo = new schema.Entity('todos',{},{ idAttribute: '_id'});
const list = new schema.Entity('lists',{todos:todo},{idAttribute: '_id'});
const normalizedData = normalize(data, list);
console.log(normalizedData);
Run Code Online (Sandbox Code Playgroud)

我一直在尝试他们的例子,但它们似乎都不适用于这些数据.

任何帮助,将不胜感激.

javascript normalizr

4
推荐指数
1
解决办法
1629
查看次数

标签 统计

javascript ×1

normalizr ×1