render 了一个数组遍历后的结果,但数组中还包含数组,不知道在 jsx 语法中如何能再次遍历这个数组让代码更加精简,其实 className 为 market-block 的 div 是可以复用的。但是我实在笨拙,没有找出更简洁的方法。
数据源:
const stockQuote = [[
{
stockName: "上证指数",
currentPrice: "3217.96",
change: "+5.51",
percent: "+0.17%"
}, {
stockName: "深圳成指",
currentPrice: "3217.96",
change: "+5.51",
percent: "+0.17%"
}, {
stockName: "创业板指",
currentPrice: "3217.96",
change: "+5.51",
percent: "+0.17%"
}
], [
{
stockName: "沪深 300",
currentPrice: "3217.96",
change: "+5.51",
percent: "+0.17%"
}, {
stockName: "中证 500",
currentPrice: "3217.96",
change: "+5.51",
percent: "+0.17%"
}, {
stockName: "上证 50",
currentPrice: "3217.96",
change: "+5.51",
percent: "+0.17%"
}
]];
代码:
render() {
const stocks = stockQuote.map((d, i) => {
return (
<Row key={i}>
<Col span={8} className="market-block-col">
<div className="market-block">
<h3>{d[0].stockName}</h3>
<p>{d[0].currentPrice}</p>
<span>{d[0].change}</span>
<span>{d[0].percent}</span>
</div>
</Col>
<Col span={8} className="market-block-col">
<div className="market-block">
<h3>{d[1].stockName}</h3>
<p>{d[1].currentPrice}</p>
<span>{d[1].change}</span>
<span>{d[1].percent}</span>
</div>
</Col>
<Col span={8} className="market-block-col">
<div className="market-block">
<h3>{d[2].stockName}</h3>
<p>{d[2].currentPrice}</p>
<span>{d[2].change}</span>
<span>{d[2].percent}</span>
</div>
</Col>
</Row>
)
});
return (
<Carousel afterChange={this.handleCarouselChanged.bind(this)}>
{stocks}
</Carousel>
);
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.