React native json值';2';无法将nsnumber类型的转换为nsstring
我正在使用从库中导入的转盘制作imageSlider:“react native banner Carousel” 我正在尝试获取本地存储在文件夹组件中的图像。我正在创建一个数组if图像,然后尝试通过旋转木马渲染它们 我肯定会遇到这样的错误:“nsnumber类型的json值“2”无法转换为nsstring” 图像滑块代码:React native json值';2';无法将nsnumber类型的转换为nsstring,react-native,carousel,React Native,Carousel,我正在使用从库中导入的转盘制作imageSlider:“react native banner Carousel” 我正在尝试获取本地存储在文件夹组件中的图像。我正在创建一个数组if图像,然后尝试通过旋转木马渲染它们 我肯定会遇到这样的错误:“nsnumber类型的json值“2”无法转换为nsstring” 图像滑块代码: const BannerWidth = Dimensions.get('window').width; const BannerHeight = 260; const i
const BannerWidth = Dimensions.get('window').width;
const BannerHeight = 260;
const images = [
require("./abc.jpg"),
require("./xyz.jpg")
];
export default class ImageSlider extends React.Component {
renderPage(image, index) {
return (
<View key={index}>
<Image style={{ width: BannerWidth, height: BannerHeight }} source={{uri:image}} />
</View>
);
}
render() {
return (
<View style={styles.container}>
<Carousel
autoplay
autoplayTimeout={5000}
loop
index={0}
pageSize={BannerWidth}
>
{images.map((image, index) => this.renderPage(image, index))}
</Carousel>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
justifyContent: 'center'
},
});
const BannerWidth=Dimensions.get('window').width;
const BannerHeight=260;
常量图像=[
要求(“./abc.jpg”),
要求(“./xyz.jpg”)
];
导出默认类ImageSlider扩展React.Component{
渲染页面(图像、索引){
返回(
);
}
render(){
返回(
{images.map((image,index)=>this.renderPage(image,index))}
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
背景颜色:“#fff”,
为内容辩护:“中心”
},
});
因此,我应该能够渲染图像数组中显示的所有图像。但我得到了这个错误。
我哪里出错了?你的问题在这里:
const images = [
require("./abc.jpg"),
require("./xyz.jpg")
];
require不返回图像的URL,而是返回媒体的内部索引。在你的例子中,我假设是2,图像的接口需要一个字符串
试试这个:
<Image style={{ width: BannerWidth, height: BannerHeight }} source={image} />