你可以使用
List
对于主界面和
Card
用于细节界面。
您的父组件将处理
List
从主界面选择更改,并负责将正确的详细数据发送到
Card
.
以下是使用Material UI组件时此结构的外观示例:
class ParentComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
currentDetailIndex: 0,
numOfListItems: 10,
detailData: [
{...},
{...},
...
]
};
}
changeDetailIndex = (newIndex) => {
this.setState({ currentDetailIndex: newIndex });
}
moveUp = () => {
if (this.state.currentDetailIndex > 0) {
this.setState({ this.state.currentDetailIndex - 1 });
}
}
moveDown = () => {
if (this.state.currentDetailIndex < this.state.numOfListItems - 1) {
this.setState({ this.state.currentDetailIndex + 1 });
}
}
onKeyPressed(e) {
if (e.keyCode == '38') {
// up arrow
this.moveUp();
}
else if (e.keyCode == '40') {
// down arrow
this.moveDown();
}
}
render() {
return (
<div>
<List component="nav" onKeyDown={this.onKeyPressed}>
<ListItem onClick={() => { this.changeDetailIndex(someIndex); }}>'s...
</List>
<Card>
<CardContent>
<SomeDetailComponent data={this.state.detailData[this.state.currentDetailIndex]} />
</CardContent>
</Card>
</div>
);
};
}