简体   繁体   English

这是一个反应本机项目。 我的编译器发现 item 变量未定义,即使我在 function 中使用了 item

[英]This is a react native project. My compiler finds the item variable to be undefined even though I used item in a function

I am trying to fix my routes in react native, to do so I'm using the item variable to navigate through my pages.我试图在本机反应中修复我的路线,为此我使用 item 变量来浏览我的页面。

<TouchableOpacity
  style={{
    padding: 20,
    flexDirection: "row",
    backgroundColor: colors.background,
    justifyContent: "flex-end",
    alignItems: "center",
  }}
  onPress={navigation.navigate("Edit", { id: item.id })}
>
  <Text style={{ fontSize: 24 }}>Task</Text>
  <MaterialCommunityIcons
    name="plus"
    size={40}
    style={{
      color: colors.themeColor,
      backgroundColor: colors.white,
      borderRadius: 20,
      marginHorizontal: 8,
    }}
  />
</TouchableOpacity>

First use {()=> navigation.navigate("Edit", { id: item.id })}.If you are not using item variables in your code it will give you undefined.首先使用 {()=> navigation.navigate("Edit", { id: item.id })}。如果你没有在你的代码中使用项目变量,它会给你未定义的。 for example, if your id variable is a person so try using person.id.例如,如果您的 id 变量是一个人,那么请尝试使用 person.id。 On the next page use route.params.person.在下一页使用 route.params.person。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Undefined 不是 function('...item.map...' 附近)-React Native 搜索栏 - Undefined is not a function (near '…item.map…')-React Native search bar 即使我刚刚使用它,FB仍未定义 - FB is undefined even though I just used it 即使条件正确且项目存在,Javascript 映射也返回未定义 - Javascript map returns undefined even though condition is correct and item exists 我正在使用 Mamp,所以我可以将 phpAdmin 用于我的 react native 项目。 如何修复根文件夹 - I'm using Mamp so I can use phpAdmin for my react native project. How can I fix the root folder 在元素列表中未定义对元素的React Native ref - React Native ref to element is undefined in flatlist item React Child 道具变量未定义,即使我之前定义了变量 - React Child prop variable is undefined even though I defined the variable before 未定义 Function 即使我在 Javascript 中定义了它 - Undefined Function Even though I defined it in Javascript 我正在更新对象,即使变量不知道 express js 中的项目更新 - I am getting updated object even though the variable has no knowledge of item update in express js 即使我在后台运行了模拟器,也无法运行我的React本机代码 - I can't run my react native code even though I have an emulator running in the back round 找不到变量React-即使未在文件中使用它 - Can't find variable React - Even though it is not used in file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM