如何在Laravel中导航JavaScript JSON对象



完全是新手。所以,我试图从JavaScript JSON中导航一些数据,但我一直得到一个错误,"导航未定义";每当我点击我的按钮。有人可以帮助我通过显示一些数据(名称,描述等)每当我点击我的touchableOpacity。

下面是我的主代码:

import React, { Component } from "react";
import {
StyleSheet,
View,
TouchableOpacity,
Text,
Image,
FlatList,
ScrollView,
} from "react-native";

import Foods from "../const/Foods";
import { SafeAreaView } from "react-native-safe-area-context";

export default class Recipes extends Component {
render() {
return (
<SafeAreaView>
<FlatList
style={styles.mainList}
data={Foods}
keyExtractor={(item) => item.id}
showsVerticalScrollIndicator={false}
renderItem={({ item }) => {
return (
<TouchableOpacity
onPress={() => {
navigation.navigate("Foods", item);
}}
>
<View style={styles.itemContainer}>
<View style={styles.itemList}>
<Text style={styles.name}>{item.name}</Text>
<Text style={styles.description}>{item.description}</Text>
<Image source={item.image} style={styles.image} />
</View>
</View>
</TouchableOpacity>
);
}}
/>
</SafeAreaView>
);
}
}
这是我的JavaScript JSON:
const foods = [
{
id: "1",
name: "Goto",
description: "Ito ay parang lugaw din",
ingredients: "Mixed Pizza",
price: "8.30",
image: require("../assets/recipes/goto.jpg"),
},
];
export default foods;

你需要在你的项目中添加导航,请查看文档如何做,以及如何正确使用导航:https://reactnavigation.org/docs/getting-started

最新更新