大家好我正在研究reactjs我是关于将我的js代码迁移到reactjs这里我有一个问题如果你想帮助我感谢提前 我把这个代码编辑好了一个好男人
{props
.data
.releases
.map((release, i) => <Fragment key={i}>
<tr>
<td colspan={acts.length}>{release.id}</td>
</tr>
<tr>
{Object
.keys(release.storiesByTasks)
.map((storyByTasksKeys, i) => <td key={i}>
<ul>
{release
.storiesByTasks[storyByTasksKeys]
.map((taskss, j) => <li key={j}>{taskss.id}</li>)
}
</ul>
</td>)
}
</tr>
</Fragment>)
}
这是数据
this.state = {
data: {
activities: [
{
id: 'A1',
tasks: [
{
id: 'A1.T1'
},
{
id: 'A1.T2'
}
]
},
{
id: 'A2',
tasks: [
{
id: 'A2.T1'
}
]
},
{
id: 'A3',
tasks: []
}
],
releases: [
{
id: 'R1',
storiesByTasks: {
'A1.T1': [
{
id: 'A1.T1.S1'
},
{
id: 'A1.T1.S2'
}
],
'A1.T2': [
{
id: 'A1.T2.S1'
},
{
id: 'A1.T2.S2'
},
{
id: 'A1.T2.S3'
}
],
}
},
{
id: 'R2',
storiesByTasks: {
'A1.T2': [
{
id: 'A1.T2.S4'
},
{
id: 'A1.T2.S5'
}
],
'A2.T1': [
{
id: 'A2.T1.S1'
}
]
}
}
]
};
在旧的js代码中我创建了一个名为taskss yellow的表,一个var taskss = [];我从数据推送所有任务,我把emty对象推入其中,所以我可以显示这样的事情
答案 0 :(得分:3)
根据您的数据,这是如何实现的:
return (
<table border="1">
<tbody>
<tr>{acts.map((cell, i) => <td key={i}>{cell != null ? cell.id : " "}</td>)}</tr>
<tr>{taskss.map((cell, i) => <td key={i}>{cell != null ? cell.id : " "}</td>)}</tr>
{
props
.data
.releases
.map((release, i) =>
<React.Fragment key={i}>
<tr><td colspan={acts.length}>{release.id}</td></tr>
<tr>
{
taskss.map((tasks, j) =>
<td key={j}>
{
tasks.id && release.storiesByTasks[tasks.id] ?
<ul>
{release.storiesByTasks[tasks.id].map((story, k) =><li key={k}>{story.id}</li>)}
</ul> : null
}
</td>
)
}
</tr>
</React.Fragment>
)
}
</tbody>
</table>
);
JSFiddle:https://jsfiddle.net/h3vj6gtu/2/#&togetherjs=lcOrSkFlET