javascript - 如何在“React Native Simple Store”中获取数组值?
问题描述
如何在“React Native Simple Store”中获取数组值?
这是我的代码:
const tryList = [];
store.get('shoppingList').then(res => (tryList = {res}));
console.log(tryList);
输出:
{
"res": [{
"price": 10,
"name": "t-shirt"
}]
}
预期输出:
[{
"price": 10,
"name": "t-shirt"
}]
解决方案
store.get('shoppingList').then(res => (tryList = {res}));
console.log(tryList)
看,当你打印tryList
它时,你会得到一个对象{"res": [{"price": 10, "name": "t-shirt"}]}
但是您需要获取 so 的值,res
以便您访问对象属性的方式类似,您必须在此处执行如下操作。
console.log(tryList.res)
# 这将给出你预期的结果。
推荐阅读
- c++ - Clang 没有找到
使用 libc++ 时的标头 - symfony - 参数 2 必须是 symfony 中的分页器实例
- c - 使用类型转换将 char 转换为 int 使 C 中的 1 变为 49 和 0 变为 48?
- codeigniter - 如何让 Parsley 检测 tinyMCE 形式的内容?
- java - 将纳秒(100 纳秒单位)转换为文件时间并在 java 中查看为日期
- gitlab - {"message": "无法发送空消息", "code": 50006} gitlab
- flutter - 如何将应用程序的状态更改为颤振中的集团
- angular - 如何以角度动态添加输入字段?
- r - 为什么我的闪亮应用在实现future::plan() 时会崩溃?
- postgresql - 无法使用 \h 或 \ 打开“帮助”?在 Windows 10 上的 psql 中。命令“更多”没有正确编写,它说