reactjs - 在 React Native 中将数组作为道具传递
问题描述
我一直在阅读很多线程,但找不到解决问题的方法。
我通过以下方式将一些参数传递给另一个 React Native 组件:
<Footer buttonsActive={{ firstButton: 'true', secondButton: 'false' }} />
当我控制台记录页脚中的参数时,我得到:
Object {
"buttonsActive": Object {
"firstButton": "true",
"secondButton": "false",
},
}
它看起来不错,但是当我尝试通过以下方式控制台记录元素时:
console.log(buttonsActive.firstButton);
我收到一个未定义的错误。在不使用 .map() 并询问 if (var == firstButton).... 的情况下访问这两个值的方法是什么?
谢谢
解决方案
我终于明白了它是如何工作的,所以可以这样发送参数:
<Footer firstButton secondButton={false} />
并且以这种方式在页脚组件中访问它们:
const Footer = (buttonStatus) => {
const firstButtonColor = (buttonStatus.firstButton ? 'black' : 'grey');
const SecondButtonColor = (buttonStatus.secondButton ? 'black' : 'grey');
我希望它有所帮助。
推荐阅读
- python - plt.subplot 中的 n += 1 是什么意思
- python - 循环构建相关数据框
- visual-studio - SSRS 2008 - 导出到 Excel 时的文档地图标签与在 SSRS 中时的工作方式不同
- php - 使用 wp_insert_user 后,Wordpress 正在发送电子邮件
- amazon-web-services - Userdata Cloudformation中资源的参考ID
- javascript - 如何在雷达图上反转比例显示(chart.js)
- java - 引起:java.lang.ClassNotFoundException:com.fasterxml.jackson.databind.exc.InvalidDefinitionException
- dart - 如何指定双精度中的小数位数?
- pandas - Pandas:如何访问内部 netapp 存储网格文件
- mysql - 连接两个 MySQL 表,然后对其中一个执行基本过滤