javascript - 如何检查布尔值是否设置为 true,然后将其推送到嵌套数组
问题描述
此时评论将被推送到数组中,但随后我单击放置的评论,并在输入字段中放置一些文本并单击添加...它应该被推送到嵌套数组中。查看评论,它应该检查 enableReply 是否设置为 true,如果是这种情况,则应将新添加的评论推送到嵌套数组中的该索引中。所以我的问题是,我该怎么做。另一种可能的选择是首先检查 enableReplyComment 是否设置为 true,然后再深入到 comments 数组,并检查image.comments.enableReply是否设置为 true。
case types.ADD_COMMENT: {
console.log(state);
return {
...state,
imageData: state.imageData.map(text => text.id === action.id ?
{
...text,
comments: [...text.comments, {comment: action.newComment, likeComment: text.toggle, enableReply: false, replyComments: [{}]}]
} : text
)
}
}
解决方案
推荐阅读
- reactjs - 使用 2 张不同的幻灯片时,幻灯片过渡组件不起作用
- html - 如何在计算图像宽度时引入边距?
- angular - Angular-8 找不到模块 [模块错误]
- python - 从cmd运行时无法在Spyder中拖放
- javascript - 行的HTML CSS表格边框颜色问题
- c++ - C++ 错误 LNK1104 无法打开文件 'system.dll' - 当我不尝试打开它时
- node.js - 预期 Iterable,但没有找到字段 \"Query.customers\
- php - 禁用特定日期
- ios - 展开唯一点击的单元格并折叠其他单元格
- javascript - Moment js在后天不显示错误消息