如何获取'React Native Simple Store'中的数组值?

How to get array values in '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"}]}

但是您需要获取 res 的值,因此您必须按照以下方式访问对象的 属性 。

console.log(tryList.res) # 这将给出您预期的结果。