You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Calendar的markedDates未标记全部日期问题求助

问题原因分析

你的markedDates存在三个关键问题:

  1. 日期格式不规范
    React Native Calendar要求日期键必须是**YYYY-MM-DD格式(月份和日期为两位数)**,你提供的2022-8-31、2022-9-12、2022-9-16都是一位数的月份/日期,和组件识别的格式不匹配,因此无法被正确标记。而能正常显示的2022-09-12、2022-09-14是符合两位数格式的。

  2. 重复的日期键
    你同时存在"2022-09-12"和"2022-9-12"两个键,对象中重复的键会被后面的覆盖,但因为后者格式错误,不会生效,还会导致数据逻辑混乱。

  3. 颜色值拼写错误
    所有rbga都是拼写错误,正确写法是rgba,这个错误可能导致背景色无法正常显示,虽然不影响标记点,但建议修正。

修正后的示例代码

markedDates={{
  "2022-09-12": {"color": "rgba(255, 255, 255, .30)", "dotColor": "#E892F8", "marked": true},
  "2022-09-14": {"color": "rgba(255, 255, 255, .30)", "dotColor": "#E892F8", "marked": true}, 
  "2022-11-07": {"color": "rgba(255, 255, 255, .30)", "dotColor": "#ED1286", "marked": true}, 
  "2022-08-31": {"color": "rgba(255, 255, 255, .30)", "dotColor": "#ED1286", "marked": true}, 
  "2022-09-16": {"color": "rgba(255, 255, 255, .30)", "dotColor": "#ED1286", "marked": true}
}}

额外建议

生成日期键时,统一使用格式化工具处理,比如date-fns的format方法或原生Intl.DateTimeFormat,确保月份和日期始终为两位数,避免手动拼接出错。

内容的提问来源于stack exchange,提问作者user18899735

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 18:25:34