嗨,我希望這是一個語法的事情... 我有一個搜索框,它將它的值傳遞給一個reducer,我想用它來過濾一些數據並返回作爲一個新的狀態,但只有數組中包含搜索值的城市。Redux過濾器數組返回新狀態
case 'FILTER_LOCATIONS' :
const data = action.serverData
.filter(cityName => {
return cityName.city.toLowerCase().indexOf(action.event) >= 0
});
console.log(data);
return state;
數據返回篩選數組,但如何更新我的狀態?
**更新
道歉,有點小菜。
serverData是樹的根,看起來有點像這樣:
serverData [{
"id": 1,
"full_name": "Eric Myers",
"city": "Sydney",
"lat": "-33.8678",
"lng": "151.2073",
"country": "Australia"
}, {
"id": 2,
"full_name": "Ruth Torres",
"city": "Simpang",
"lat": "-7.1406",
"lng": "107.0033",
"country": "Indonesia"
}, {
"id": 3,
"full_name": "Kevin Collins",
"city": "Herrljunga",
"lat": "58.0774",
"lng": "13.0266",
"country": "Sweden"
}]
結果數組在哪裏進入狀態?請編輯您的問題以包含狀態樹的簡要說明/示例。 –