React native 反应本机:数组中的渲染代码不渲染
我的RN 0.62.2应用程序在屏幕上以2列的形式呈现上传的图像,每个图像在一个正方形中。上载2个图像时,以下渲染代码可以正常工作:React native 反应本机:数组中的渲染代码不渲染,react-native,jsx,React Native,Jsx,我的RN 0.62.2应用程序在屏幕上以2列的形式呈现上传的图像,每个图像在一个正方形中。上载2个图像时,以下渲染代码可以正常工作: return ( <Grid style={{position:"absolute", paddingTop:0,paddingLeft:0}}> //<<==wrap in Grid <
return (
<Grid style={{position:"absolute", paddingTop:0,paddingLeft:0}}> //<<==wrap in Grid
<Row style={{paddingTop:0}}> //<<==2 images shown in one row
<Col style={{position:"absolute", marginTop:0}}> //<<==2 columns
{displayImg(pics[0].path, screen_width*half, screen_width*half, 0, screen_width, pics[0].height*(screen_width/pics[0].width))} //<<==method to display one image
</Col>
<Col style={{position:"absolute", left:Math.ceil((screen_width-20)/2), paddingTop:0}}>
{displayImg(pics[1].path, screen_width*half, screen_width*half, 1, screen_width, pics[1].height*(screen_width/pics[1].width))}
</Col>
</Row>
</Grid>
);
通过上传2张图片进行测试,没有返回任何内容,应用程序挂起。重构有什么问题吗?您的变量
行
是数组,所以您必须映射到它才能显示
返回(
// 通过执行以下操作解决了问题:
return (
<Grid style={{position:"absolute", paddingTop:0,paddingLeft:0}}>
<Row style={styles.row}>
{pics.map((item, index) => {
return (displayImg(item.path, screen_width*half, screen_width*half, index, screen_width, item.height*(screen_width/item.width)))
})}
</Row>
</Grid>
);
返回(
{pics.map((项目,索引)=>{
返回(显示img(item.path、screen\u width*half、screen\u width*half、index、screen\u width、item.height*(screen\u width/item.width)))
})}
);
地图
对同样的问题没有帮助。
return (
<Grid style={{position:"absolute", paddingTop:0,paddingLeft:0}}>
<Row style={styles.row}>
{pics.map((item, index) => {
return (displayImg(item.path, screen_width*half, screen_width*half, index, screen_width, item.height*(screen_width/item.width)))
})}
</Row>
</Grid>
);