Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 我想渲染的图像和图像的数量应该在反应本机洗牌?怎么做?有人能帮我吗_Reactjs_React Native_User Interface - Fatal编程技术网

Reactjs 我想渲染的图像和图像的数量应该在反应本机洗牌?怎么做?有人能帮我吗

Reactjs 我想渲染的图像和图像的数量应该在反应本机洗牌?怎么做?有人能帮我吗,reactjs,react-native,user-interface,Reactjs,React Native,User Interface,当我在react native中单击特定图像时,图像应该是随机的。您可以使用lodash库的随机播放,也可以使用随机播放功能。 在下面的示例中,我将图像URL作为一个数字 函数洗牌(数组){ var currentIndex=array.length,temporaryValue,randomIndex; //虽然还有一些元素需要洗牌。。。 而(0!==currentIndex){ //选择剩余的元素。。。 randomIndex=Math.floor(Math.random()*curren

当我在react native中单击特定图像时,图像应该是随机的。

您可以使用lodash库的随机播放,也可以使用随机播放功能。 在下面的示例中,我将图像URL作为一个数字

函数洗牌(数组){
var currentIndex=array.length,temporaryValue,randomIndex;
//虽然还有一些元素需要洗牌。。。
而(0!==currentIndex){
//选择剩余的元素。。。
randomIndex=Math.floor(Math.random()*currentIndex);
currentIndex-=1;
//并将其与当前元素交换。
临时值=数组[currentIndex];
数组[currentIndex]=数组[randomIndex];
数组[randomIndex]=临时值;
}
返回数组;
}
//像这样使用
var-arr=[2,11,37,42];
arr=随机播放(arr);
控制台日志(arr)