gpt4 book ai didi

javascript - React Native 数组映射与多维数组

转载 作者:行者123 更新时间:2023-12-03 07:01:43 24 4
gpt4 key购买 nike

我需要通过多维数组进行映射,如下所示:

var array=[["1"],["3","8"],["4","8","3"],["4","8","3","9"],["1","8","3","9","2"],["6","8","3","9","2","1"],["4","8","3","9","2","11","2"]]

此代码当前仅映射数组的“列”。

var theValue = array.map((key, idx) => {
if (key === this.state.active) {
return <Main key={key + 'd'} dummy={true} />;
} else {
if (!this.state.restLayouts[idx]) {
var onLayout = function(index, e) {
var layout = e.nativeEvent.layout;
this.setState((state) => {
state.restLayouts[index] = layout;
return state;
});
}.bind(this, idx);
}
return (
<Main
key={key}
id={key}
openVal={this.state.openVal}
onLayout={onLayout}
restLayout={this.state.restLayouts[idx]}
onActivate={this.setState.bind(this, {
active: key,
activeInitialLayout: this.state.restLayouts[idx],
})}
/>
);
}
});

最佳答案

这是将二维数组映射到表中的快速示例。使用 Flexbox 基于每行元素数量的动态宽度:

<table style={{ display: 'flex', flexDirection: 'column' }}>
<tbody>
{
array.map(arr => {
if (arr === this.state.active) {
return (
<tr style={{ display: 'flex', justifyContent: 'space-around'}}>
{
arr.map(datum => {
return (<th>{datum}</th>);
}
}
</tr>
);
} else {
return (
<tr style={{ display: 'flex', justifyContent: 'space-around'}}>
{
arr.map(datum => {
return (<td>{datum}</td>);
}
}
</tr>
);
}
))
}
</tbody>
</table>

关于javascript - React Native 数组映射与多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37023000/

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