【发布时间】:2021-08-19 14:08:46
【问题描述】:
我正在使用react-bootstrap,我想知道是否可以根据代码动态转到下一行。让我告诉你我想要做什么:
// components/WeatherList.js
import React from 'react'
import { Col, Row } from 'react-bootstrap'
import WeatherCard from './WeatherCard'
const WeatherList = ({weathers}) => {
console.log("e")
console.log(weathers)
return (
<Row>
{weathers.list.map(({dt, main, weather}) => (
<Col key={dt}>
<WeatherCard
dt={dt * 1000}
temp_min={main.temp_min}
temp_max={main.temp_max}
humidity={main.humidity}
temp={main.temp}
main={weather[0].main}
city={weathers.city.name}
country={weathers.city.country}
/>
</Col>
))}
</Row>
)
}
export default WeatherList;
我每天最多得到 5 个预测(所以 5 张卡片),但如果我只得到 2 个预测,我想在第二天换一个新行。在您可以看到的图片上,我想在日期变化时动态创建一个新行:
我该怎么做?
【问题讨论】:
-
你的
dt对象是什么,以毫秒为单位的日期? -
好吧,我会每天对卡片进行分组,然后将每一天都呈现为新行,其中包含分组卡片
-
@TumoMasire 是的
-
@TheReason 这是个好主意
-
@TheReason 如果您有任何样品可以帮助我,我将不胜感激,我目前正在解决您的想法
标签: reactjs react-bootstrap bootstrap-grid