我有一個這樣的對象:陣營減速(添加對象鍵對象)
const fruits = {
"Orange": { "price": 0.25, "inventory": 10},
"Banana": { "price": 0.30, "inventory": 10},
"Apple": { "price": 0.95, "inventory": 10},
}
,我想寫減速讓對象是這樣的:
const fruits = {
"Orange": { name: "Orange", "price": 0.25, "inventory": 10},
"Banana": { name: "Banana", "price": 0.30, "inventory": 10},
"Apple": { name: "Apple", "price": 0.95, "inventory": 10},
}
我減速機:
const fruitsByName = (state = {}, action) => {
switch (action.type) {
case "RECEIVE_FRUITS":
return action.products
default:
return state
}
}
請幫助我,我覺得我已經嘗試了一切。