Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通知和#x27;在收到通知后你不会离开吗?_Javascript_Reactjs_Redux_Jsx - Fatal编程技术网

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
})