reactjs - Normalizr :如果 id 存在,则仅将项目添加到项目数组
问题描述
如何防止向实体添加值或将其推送到items
数组?
我尝试undefined
从中返回idAttribute
,但它仍然将 推送到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
. 有没有办法可以做到这一点?
谢谢
解决方案
更新
const getGuid = (entity: any) => {
if (entity && entity.enclosure) {
if (entity && entity.guid) {
return entity.guid
} else if (entity && entity.enclosure && entity.enclosure.url) {
return entity.enclosure.url
}
}
}
推荐阅读
- node.js - http-server 在后台运行
- android - 如何在android中设置一个按钮来切换带有动画的图像?
- python - 具体的 Python 2 到 Python 3 的转换头疼
- javascript - 如何在赛普拉斯的 Chrome 上访问网络呼叫?
- java - 错误:无法解析“:app@debug/compileClasspath”的依赖关系:无法解析androidx.appcompat:appcompat:1.1.0
- react-native - React-native:如何检查它是否是用户的第一个连接?
- python - clickhouse + sqlalchemy:SELECT 从结果中删除两行
- java - Spring security csrf disabled,仍然得到一个 Invalid CSRF token found
- python - 如何为层中的每个节点为 Keras relu 函数分配自定义 alpha?
- qt - 将 QListWidgetItem CheckState(toggled on) 上的默认 plastique 小部件样式更改为右勾而不是交叉勾