【问题标题】:JSX If a value in a array of Dictionaries is the same, show a messageJSX 如果字典数组中的值相同,则显示一条消息
【发布时间】:2018-09-11 21:00:58
【问题描述】:

我有一组字典,它们是我显示的小组会议,以防所有小组会议都标记为不公开,我想改为显示一条消息。

我已经有一条消息显示是否没有群组,但如果有群组但没有公开群组,我还想要一条显示不同消息的消息。

下面是我正在使用的代码。

  <div className="sk-asset sk-groups">
      {profile.group_sessions.length > 0 ? profile.group_sessions.reverse().map(group => (
        <div key={group.id}><GroupsCards group={group} /></div>))
    : <p style={{ textAlign: 'center', fontSize: 25 }}>More groups coming soon to your area</p> }
  </div>

我的想法是在数组中循环,看看它们是否都设置为 is_public = false,但不知道该怎么做。如果有人有更好的建议,我完全赞成。感谢您的关注!

【问题讨论】:

    标签: arrays reactjs loops dictionary jsx


    【解决方案1】:

    使用过滤器检查结果数组是否为空。

    if (profile.group_sessions.filter(group => group.is_public).length === 0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 2021-09-25
      相关资源
      最近更新 更多