我正在使用以下架构:
import { schema } from 'normalizr';
import { guid } from '../utils/guid';
const track = new schema.Entity('audioTracks');
const audioClip = new schema.Entity('audioclips', {
audioclips: [track],
}, {
idAttribute: (entity, parent) => `${parent.id}:${entity.id}`,
});
const segment = new schema.Entity('segments', {
audioclips: [audioClip],
}
);
const program = new schema.Entity('programs', {
segments: [segment],
});
const json = new schema.Entity('jsons', {
programs: [program],
});
export const portalAttributes = new schema.Entity('portalAttributes');
export const experience = new schema.Entity('experiences', {
json,
portalAttributes,
});
我的数据在音频剪辑部分使用相同的 id,我不想合并。因为它们最终将包含唯一的数据。规范化部分按预期工作,但是当我尝试将数据反规范化时,它失败并出现以下错误:
TypeError: Cannot read property 'id' of undefined
at EntitySchema.idAttribute (http://localhost:4040/main.bundle.js:3782:59)
at EntitySchema.getId (http://localhost:4040/vendor.bundle.js:70706:19)
at unvisitEntity (http://localhost:4040/vendor.bundle.js:4787:19)
at unvisit (http://localhost:4040/vendor.bundle.js:4821:14)
at http://localhost:4040/vendor.bundle.js:70589:12
at Array.map (native)
at denormalize (http://localhost:4040/vendor.bundle.js:70588:37)
请帮助将数据反规范化。
我在这个阶段所做的就是:
const normalized = normalize(payload, norm.experience);
const denorm = denormalize(normalized.result, norm.experience, normalized.entities)
我也可以按需提供输入数据,它有点大。