我正在使用react.js而且我有:console.log(JSON.stringify(this.props.currentCart));
返回给我:
{
"_id": "58f7368b42987d4a46314421",
"userID": "58f7368a42987d4a46314420",
"__v": 0,
"items": [
{
"quantity": 1,
"itemID": "58f6138d734d1d3b89bbbe31",
"_id": "58f751ae3a00495f69145ae6"
},
{
"quantity": 1,
"itemID": "58f5ff55734d1d3b89bbb4a4",
"_id": "58f755903a00495f69145ae7"
}
]
}
如何遍历每个项目并检索每个项目的itemID(在这种情况下为58f6138d734d1d3b89bbbe31
和58f5ff55734d1d3b89bbb4a4
)?
我试过几种方式,这是我最后一次徒劳的尝试:
this.props.currentCart.items.forEach(function(item){
console.log(item.itemID)
});