简体   繁体   English

如何在 React 组件中修复列表样式计划的渲染

[英]How to fix rendering on a list-style schedule in React component

I am trying to create a 'simple' schedule of events for a React app.我正在尝试为 React 应用程序创建一个“简单”的事件时间表。 I'm using this Codepen for inspiration.我正在使用这个 Codepen来获得灵感。 There aren't events for every day and some days have more events than others.不是每天都有活动,有些日子的活动比其他日子多。

I was finally able to create one 'date' header (on the left) for each date, without repeating, and to then display one time block on the right for all of the events in that day.我终于能够为每个日期创建一个“日期”header(在左侧),无需重复,然后在右侧为当天的所有事件显示一个时间块。 However, I can't get it to render properly.但是,我无法让它正确渲染。 I've tried everything I can think of in terms of padding, margins, alignment, etc. I've also tried moving things into and out of different divs to see if that was the issue.我已经尝试了所有我能想到的填充、边距、alignment 等。我还尝试将事物移入和移出不同的 div 以查看是否是问题所在。

I'm not sure how to get this issue to display in a Codepen or JSFiddle with the JSX and React components, etc. I've copied the code into this Codepen regardless -- hopefully it's enough to convey the issue.我不确定如何使用 JSX 和 React 组件等在 Codepen 或 JSFiddle 中显示此问题。无论如何,我已将代码复制到此 Codepen 中——希望它足以传达问题。 This is the main relevant section:这是主要的相关部分:

  render() {
this.restructureData();
return (
  <div>
    <br></br>
    <h1>Availability</h1>
    {/* {this.renderTimeslots()} */}
    <div className="schedule-div">
      <ul className="main">{this.betterRenderTimeslots()}</ul>
    </div>
  </div>
);

  betterRenderTimeslots = () => {
const newObject = this.restructureData();
let allDays = [];
for (let date in newObject) {
  let onThisDay = (
    <>
      <h3>{date}</h3>
      <li className="events">
        <ul className="events-detail">
          {newObject[date].map(timeslot => {
            return (
              <li>
                {<span className="event-time">{timeslot.hour}:00</span>}
              </li>
            );
          })}
        </ul>
      </li>
    </>
  );
  allDays.push(onThisDay);
}
return allDays;

}; };

The accompanying CSS is pasted into the Codepen above.随附的 CSS 粘贴到上面的 Codepen 中。 Here's a screenshot of what it looks like for me.这是我的屏幕截图 Thank you!谢谢!

Your H3 header is not inside LI element, that's why it's falling out您的H3 header 不在LI元素内,这就是它掉出的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM