深度嵌套obj的Normalizr用法

时间:2019-03-09 19:37:43

标签: json ngrx normalizr

我正在尝试使用Normalizr对我的angular ngrx应用程序中使用的对象进行规格化和非规格化。

我在这里找到了几乎可以解决的方法:https://www.snip2code.com/Snippet/1028240/Deep-nested-tree-normalize-with-normaliz

var node = new Schema('nodes');
node.define({
    children: arrayOf(node)
});
var treeSchema = arrayOf(node);


var normalizedData = normalize(data, treeSchema);
console.log(normalizedData);

问题是以下解决方案中的许多功能都发生了变化,而使用更高版本的normalizr使用相同的解决方案对我来说有点困难。也许有些人知道如何将以下解决方案重写为新的normalizr?

{{1}}

2 个答案:

答案 0 :(得分:1)

您正在查看使用过时版本的Normalizr的示例。尝试阅读the docs以获得新的API

答案 1 :(得分:0)

我做到了:)

 const node = new schema.Entity('nodes');
    node.define({
        children: [node]
    })
    const treeSchema = [node];
    const normalizedData = normalize(this.form,treeSchema);