我正在使用reactnative用于移动应用程序并遇到了问题 我有json文件,我需要在js文件中。 在json文件中还有很多图像路径。 当我从我的js文件中的文件夹中要求json文件时 然后将改变json文件中的图像的路径, 而且我也无法在require方法中传递动态字符串。
这是我在JSON文件中的代码:
{
"Industry": [
{
"Id": "1",
"UpperImg": "../../../uploads/bposervices/industry/Bankingimg.png",
"FiledName": "Financial Services",
"FileName": "FS.json",
"Url" :"uploads/json/FS.json"
},
{
"Id": "2",
"UpperImg": "../../../uploads/bposervices/industry/Insimg.png",
"FiledName": "Insurance",
"FileName": "Insurance.json",
"Url" :"uploads/json/Insurance.json"
}
],
"Enterprises": [
{
"Id": "1",
"UpperImg": "uploads/bposervices/enterprise/Faimg.png",
"FiledName": "Finance & Accounting",
"FileName": "FandA.json",
"Url" :"uploads/json/FandA.json"
},
{
"Id": "2",
"UpperImg": "uploads/bposervices/enterprise/Spimg.png",
"FiledName": "Sourcing & Procurement",
"FileName": "SandP.json",
"Url" :"uploads/json/SandP.json"
}
]
}
这是我的js文件:
const abc = require('../../folder/a.json)
class B extends component {
render() {
return (
<Container style={styles.container}>
<Content>
<List
dataArray={abc.industry} renderRow={dataIndustry =>
<ListItem>
<Card>
<CardItem cardBody>
<Image source={dataIndustry.UpperImg}/>
// or <Image source ={require(dataIndustry.UpperImg)/>
</CardItem>
<CardItem>
<Text>{dataIndustry.FiledName}</Text>
</CardItem>
</Card>
</ListItem>
}
/>
</Content>
</Container>
);
}
}
当我迭代json文件的对象数组时, 我得到了我传递的图像路径require方法, 但它不接受require中的动态图像路径 方法既不在图像源中。
任何人都可以建议我如何才能得到相同的结果?