我最初返回對象的數組,沒有密鑰這樣每個對象的API /終極版陣列:陣營與鍵映射
[
{
"id": 4311,
"title": "C43- Miami Bow Cabinet Handles High Quality Stainless Steel (Polished) Handles",
"liked": false
},
{
"id": 2235,
"title": "C43- Miami Bow Cabinet Handles High Quality Stainless Steel (Brushed) Handles",
"liked": false
}
]
但是它會幫助我的應用程序很多,如果我可以存儲此數據與ID爲每個嵌套對象的關鍵,我已經更新了我的API,以這樣的返回數據:
{
"2235": {
"title": "C43- Miami Bow Cabinet Handles High Quality Stainless Steel (Brushed) Handles",
"liked": false
},
"4311": {
"title": "C43- Miami Bow Cabinet Handles High Quality Stainless Steel (Polished) Handles",
"liked": false
}
}
但是現在我得到反應的錯誤 - 「props.posts.map不是一個函數'
我不明白什麼改變了數據,doesnt redux爲每個對象分配一個數字鍵,如果一個沒有設置反正呢?
這不是一個數組anymo回覆。但是您可以使用[Object.entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)或[Object.keys](https:// developer .mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) –
我想你想看看[normalizr](https://github.com/paularmstrong/normalizr) – Okazari