【发布时间】:2019-11-23 21:15:39
【问题描述】:
如何防止向实体添加值或将其推送到items 数组?
我尝试从idAttribute 返回undefined,但它仍然将undefined 推送到items 数组中,并且还在实体中添加了一个名为undefined 的键。
const getGuid = (entity: any) => {
if (entity.enclosure) {
if (entity.guid) {
return entity.guid
} else if (entity.enclosure.url) {
return entity.enclosure.url
}
}
}
const fetchPodcastRssEpisodeSchema = new schema.Entity(
'episodes',
{},
{
idAttribute: getGuid,
processStrategy: (entity, parent, _key) => {
const itunes = entity.itunes || {}
const enclosure = entity.enclosure || {}
const image =
itunes.image ||
(parent.image && parent.image.url) ||
(parent.itunes && parent.itunes.image)
return {
artist: parent.title,
content: entity.content,
durationSeconds: utils.transformDurationToSecs(itunes.duration),
guid: getGuid(entity),
image,
pubDate: entity.isoDate,
title: entity.title,
url: enclosure.url,
}
},
}
)
只有在从idAttribute 返回有效值时才应添加该项目。有什么办法可以实现吗?
谢谢
【问题讨论】:
-
你能展示一下代码吗?
标签: reactjs redux react-redux normalizr