我在flatlist中使用flatlist,我想获取我
在下面的代码中使用的第一个flatlist的索引:
<FlatList
data ={this.state.data}
renderItem = {(item, index1)=>
<View>
<FlatList
data = {this.state.data2}
renderItem = {(item, index2) =>
console.log("parent_index",index1);
console.log("child_index",index2);
}
/>
</View>
}
我如何获得index1?
我在上面的代码中所做的是未定义的。
第一份清单的代码
render() {
return (
<View style={{ height: "100%", width: "100%", backgroundColor: 'red' }}>
<FlatList
data={this.state.data}
renderItem={({ item, index }) => {
return (
this.renderSecondFlatlist(index)
);
}
}
/>
</View>
)
}
第二个flatList的代码,您将在其中传递第一个FlatList的“索引”
renderSecondFlatlist(index1) {
return (
<View style={{ flex: 1, backgroundColor: 'pink' }}>
<FlatList
data={this.state.data2}
renderItem={(item, index2) => {
/*return (
<Text>{index1}</Text>
);*/
console.log("index:-",index1);
}
}
/>
</View>
);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句