javascript - ReactJS:在两列中呈现数据
问题描述
我有这个组件:
export const RenderDetail = props => {
const createRows = props.content.reduce(function (rows, key, index) {
console.log('rows, key, index', rows, key, index);
return (index % 2 === 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) && rows;
}, []);
return (
<div>
{createRows.map((row, index) => {
return (
<div key={`item_${index}`}>
<Row>
{row.map((col, key) => {
return (
console.log('col ', col),
(
<div key={`item_${key}`} style={{ margin: '20px' }}>
<Col>
<dl className="jh-entity-details">
<dt>
<span id={col.id}>{col.name}</span>
</dt>
<dd>{col.value}</dd>
</dl>
</Col>
</div>
)
);
})}
</Row>
</div>
);
})}
</div>
);
};
我将一个 Object 数组传递给该组件,例如:
const Container = [
{
id: "id",
name: "ID",
value: "10"
},
]
我会得到什么:
我想把数据分成两列,但这样它们太近了,粘在一起了。有没有办法表示它们,以便它们占据整个页面(总是在两列中?)
编辑:
<Col xs="12" md="6">
按照建议使用
解决方案
我改变了你的沙箱。检查新的
问题出在这部分代码
<div key={`item_${key}`} style={{ margin: '20px' }}>
<Col>
首先,我删除了div
包含Col
标签的内容,然后将 6-grid 属性设置为 50% 的宽度。
推荐阅读
- python - 来自守护进程的错误响应:OCI 运行时创建失败:container_linux.go:380:启动容器进程导致:exec:“python”:
- delphi - 是否可以在 Delphi 中声明具有通用值类型的 TDictionary?
- filter - WP过滤器/动作
- discord - Discord.js - 音频资源无法正常播放
- ruby-on-rails - Ruby 将整数拆分为整数数组
- c++ - 您将如何对动态二维数组中的元素进行洗牌?
- c++ - CMake 找不到“PocoDataPostgreSQL”提供的包配置文件
- reactjs - 无法导入gql
- python - 硒庙钱包点击
- reactjs - 引导模式没有得到反应状态