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文檔。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);
這隻會導致對「結果」對象的相同響應,而實體對象爲空。有人可以幫幫我嗎。首先,我正在努力使郵政正常化,然後再評論。但是我還沒有能夠跨越第一步。
謝謝..它的工作。你能否詳細解釋它是如何工作的。就像iIalso想要標準化Comment一樣。隨着最近嘗試進入Redux架構,除非正確理解,否則一切看起來都很混亂/魔幻。再次感謝。 – user98239820
@ user98239820我添加了一些有用的示例 –