我在文件夹 assets/dummy-data/Avatars.ts 中创建了一个名为 avatars 的虚拟数据文件。
export default [
{id: 1, levels: ["pichu", "picachu", "raichu"]},
{id: 2, levels: ["charmander", "charmeleon", "charizard"]},
{id: 3, levels: ["totodile", "croconaw", "feraligatr"]},
{id: 4, levels: ["squirtle", "wartortle", "blastoise"]},
{id: 5, levels: ["bulbasaur", "ivysaur", "venusaur"]},
{id: 6, levels: ["cyndaquil", "quilava", "typhlosion"]},
{id: 7, levels: ["pidgey", "pidgeotto", "pidgeot"]},
{id: 8, levels: ["turtwig", "grotle", "torterra"]},
{id: 9, levels: ["igglybuff", "jigglypuff", "wigglytuff"]},
{id: 10, levels: ["cleffa", "iclefairy", "clefable"]},
{id: 11, levels: ["litten", "torracat", "incineroar"]},
{id: 12, levels: ["nidoran", "nidorina", "vnidoqueen"]},
]
我想要做的是将这些数据加载到另一个文件中,然后用它们制作一个 Flatlist 组件。我的代码是:
import { StyleSheet, Text, View, FlatList, Image } from 'react-native'
import Avatars from '../assets/dummy-data/Avatars'
const OnboardingScreen = () => {
const test = "charizard"
console.log(Avatars)
return (
<View>
<FlatList
data = {Avatars}
renderItem = {
({item}) =>
(
<Image source={require(`../assets/images/avatars/${{item}.levels[0]}pichu.jpg`)} />
)
}
/>
</View>
)
}
export default OnboardingScreen
const styles = StyleSheet.create({})
这是我得到的错误: 错误的屏幕截图
谢谢