1
import { normalize, Schema, arrayOf } from 'normalizr';

var ListA = [
    {
        id:1, 
        text: "text1",
        comments : [
            {
                id: 232,
                text: "asfasd"
            },
            {
                id: 333,
                text: "abcsss"
            }
        ]
    }, 
    {id:2, text:"text2", comments:[]}, 
    {id:3, text:"text3", comments:[]}
    ]

この単純な応答を正規化しようとしています。私がやっていることのどこが悪いのかわからないか、normalizr のドキュメントを理解していません。

const post = new Schema('posts');
// const comment = new Schema('comments');
// const collection = new Schema('collections');

// post.define({
//  comments : comment,
//  collections : arrayOf(collection)
// });
ListA = normalize(ListA, {
    posts: arrayOf(post)
});

console.log(ListA);

これにより、「結果」オブジェクトで同じ応答が返され、エンティティ オブジェクトは空になります。誰か助けてください。最初に投稿だけを正規化しようとしていますが、その後もコメントになります..しかし、最初のステップを越えることができませんでした。

4

1 に答える 1