reactjs - react-native 如何根据点击的手风琴从状态中收集不同的属性?
问题描述
如何从我的菜单数组中收集“标题”和“副标题”并将其传递给 onSelect 函数以根据这些参数在全页屏幕中呈现该标题和副标题?我用不同的道具做了一个手风琴。我想从每个手风琴导航到 fullPage 屏幕,这将根据我点击的手风琴呈现不同的标题和副标题。任何想法?提前致谢
export default class AccidentScreen extends Component {
constructor(props) {`super(props);
this.state = {`menu: [
{
title: 'title1', icon: 'fire', color:
Colors.customRed,
data: [
{id: '1', subtitle: 'subtitle1' , subIcon: 'fire',
status: 'inactive'},
]
},
{
title: 'title2', icon: 'street-view', color:
Colors.customLightBlue,
data: [
{id: '2', subtitle: 'subtitle2' , subIcon: 'google-
wallet', status: 'inactive' },
]
},
{
title: 'title3', icon: 'water', color:
Colors.customBrown,
data: [
{id: '3', subtitle: 'subtitle3', subIcon: 'earth',
status: 'inactive'},
{id: '4', subtitle: 'subtitle4', subIcon: 'earth',
status: 'inactive'},
]
},
{
title: 'title4', icon: 'fire', color:
Colors.customGrey,
data: [
{id: '5', subtitle: 'subtitle5', subIcon: 'wind',
status: 'inactive' },
{id: '6', subtitle: 'subtitle6' , subIcon: 'wind',
status: 'inactive'},
]
},
{
title: 'title5', icon: 'car-crash', color:
Colors.customRed,
data: [
{id: '7', subtitle: 'subtitle7',subIcon: 'car',
status: 'inactive'},
{id: '8', subtitle: 'subtitle8', subIcon: 'car',
status:
'inactive'},
]
},
]`
}
}
render() {
return (
<View style={styles.container}>
<ScrollView>
{this.renderAccordians()}
<UrgentCall/>
</ScrollView>
</View>
);
}
renderAccordians = () => {
const items = [];
for (item of this.state.menu){
items.push (
<Accordian
subtitle={item.subtitle}
title={item.title}
data={item.data}
menu={item.icon}
color={item.color}
onSelect={() => {
this.props.navigation.navigate({routeName: 'FullPage',
params: {accidentState: item} });
}} />
);
}
return items;`
}
};
解决方案
You have already helped me a lot. How could my 'Full Page Screen' know which subtitle in accordion I clicked on to pass that subtitle to 'Full Page' screen based on your first solution because the second one doesn't work.
My 'Full Page' screen component:
render() {
const accident = this.props.navigation.getParam('accidentCat');
return (
<ScrollView>
<View>
<View>
<Text>{accident.title}</Text>
<Text>{accident.data[0].subtitle}</Text>
</View>
</View>
</ScrollView>
) }
推荐阅读
- c# - 更改特定端点的 api 路由
- javascript - Angular12 - 将函数传递给组件并处理结果
- javascript - 如何获取 IP 和使用地理定位 api
- flask - 如何使用 Flask-User 创建账户持有者和子用户
- python - 如何在 keras 中构建自定义 ConvLSTM 层
- symfony - Symfony UID - How to save the ID as base32?
- java - Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet
- c++ - Is there a way to tell Clang/GCC that a single-element struct should be passed exactly like its element type and not using the struct ABI?
- javascript - How to pass index value to another component in angular?
- node.js - 使用 CRACO 托管的 React SPA:致命错误:接近堆限制的无效标记压缩分配失败 - JavaScript 堆内存不足