gpt4 book ai didi

javascript - ES6 React JS 方法日历组件

转载 作者:行者123 更新时间:2023-12-03 06:44:18 26 4
gpt4 key购买 nike

我正在创建一个日历组件,目前无法弄清楚为什么 React 不会将我的 renderWeekDays 返回的元素渲染到 DOM方法?

目前我有以下内容:

export default class CalendarApp extends React.Component {

constructor() {
super();

// Bind Methods
this.renderWeekDays = this.renderWeekDays.bind(this);
}

renderWeekDays() {
return (
<tr><td>Render Week days Please</td></tr>
)
}

render() {
let overviewContent,
checkRates

// Add Check rates and availability section if Rooms page
if (this.props.roomPage) {
checkRates = (
<div>
<h2>Check rates and availability</h2>
<small>or call us on <a href="tel:03301003180">0330 100 3180</a></small>
</div>
)
}

// Determine whether to show placeholder or actual dates
if (this.props.dateSelected) {
overviewContent = (
<div>
<span className="icon">Icon</span>
<span className="date-from">21 Jun</span>
<span className="seperate">-></span>
<span className="date-to">25 Jun</span>
<span className="clear">X</span>
</div>
)
} else {
overviewContent = (
<div>
<span className="icon">Icon</span>
<span className="check-in">Check-in</span>
<span className="seperate">-></span>
<span className="check-out">Check-out</span>
</div>
)
}

return (
<div className="calendar hotelroom-follow-calendar">
{ checkRates }
<div className="calendar-overview">
<button>
{ overviewContent }
</button>
</div>
<div className="calendar-container">
<div className="calendar-month">
<span className="previous">Prev</span>
June
<span className="next">Next</span>
</div>
<table className="calendar-table">
<thead>
<tr>
<td>M</td>
<td>T</td>
<td>W</td>
<td>T</td>
<td>F</td>
<td>S</td>
<td>S</td>
</tr>
</thead>
<tbody>
{ this.renderWeekDays }
</tbody>
</table>
</div>
{ Moment().format() }
</div>
)
}

我没有遇到任何错误,它根本无法加载到 <tr><td>Render Week days Please</td></tr> .

任何帮助将不胜感激,因为我已经仔细检查了所有bind()方法等。

最佳答案

您需要实际调用 jsx 中的函数。

<tbody>
{ this.renderWeekDays }
</tbody>

需要

<tbody>
{ this.renderWeekDays() }
</tbody>

瞧,它应该可以工作!

关于javascript - ES6 React JS 方法日历组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37814525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com