【发布时间】:2021-09-27 17:49:43
【问题描述】:
我想知道在调用我的 shuffle 函数后如何更新平面列表。我已经尝试在平面列表中使用“ExtraData”标签,但没有让它工作。任何帮助将不胜感激!
const Display = (props) => {
return (
<View>
<View style={{ flexDirection: 'row' }}>
<Image source={props.img} style={{ width: 200, height: 200 }} />
<Text>{props.title}</Text>
</View>
</View>
);
}
function Other({ navigation }) {
function Shuffle(array){
let x, y, z;
for(x = 0; x<=2;x++){
y = Math.floor(Math.random() * 3)
z=array[x];
array[x] = array[y]
array[y] = z
} console.log(array)
}
let Games = [
{ title: "Tic Tac Toe", img: require("./pics/tictac.png") },
{ title: "Connect Four", img: require("./pics/ConnectFour.jpg") },
{ title: "Monopoly", img: require("./pics/mono.png") },
];
return (
<View>
<FlatList data={Games} renderItem={({ item }) => <Display source={item} title={item.title} img={item.img}> </Display>} />
<Button title="Shuffle" onPress={() => {Shuffle(Games)}} />
</View>
);
}
【问题讨论】:
标签: reactjs react-native react-native-flatlist