Javascript 通知和#x27;在收到通知后你不会离开吗?
这是导航栏中的“我的通知”图标标记,在读取通知后不会删除包含未读通知计数的标记:Javascript 通知和#x27;在收到通知后你不会离开吗?,javascript,reactjs,redux,jsx,Javascript,Reactjs,Redux,Jsx,这是导航栏中的“我的通知”图标标记,在读取通知后不会删除包含未读通知计数的标记: const notificationsIcon = notifications && notifications.length && notifications.filter(n => !n.read).length ? <Badge badgeContent={notifications.filter(n => !n.read).len
const notificationsIcon =
notifications && notifications.length && notifications.filter(n => !n.read).length ?
<Badge badgeContent={notifications.filter(n => !n.read).length}>
<NotificationsIcon /> //Material-UI Icon
</Badge> : <NotificationsIcon />
notificationsIcon
变量将被包装在带有材质UI元素IconButton
的render方法中,单击该元素可将操作发送到redux存储,以将通知read
属性更改为true,这将更新组件中的通知。我尝试此操作只是为了测试您的第一个逻辑,这项工作:
let notificationsIcon;
if (notifications && notifications.length > 0) {
notifications.filter(n => n.read === false).length > 0
? (notificationsIcon = (
<Badge
badgeContent={
notifications.filter(n => n.read === false).length
}
>
<NotificationsIcon />
</Badge>
))
: (notificationsIcon = <NotificationsIcon />);
} else {
notificationsIcon = <NotificationsIcon />;
}
let notifications=[{read:true},{read:true}]
施工通知=
notifications&¬ifications.length&¬ifications.filter(n=>!n.read).length?
“是”:“否”;
控制台日志(通知SICON)代码>
const mapStateToProps = state => ({
notifications: state.user.notifications
})