我使用Redux从我的后端获取数据。将滤镜应用于ajax数据
componentWillMount() {
this.props.dispatch(fetchPlaces())
}
和我的行动:
export function fetchPlaces() {
return function(dispatch) {
dispatch({type: "FETCH_PLACES"});
let path = "/server/places"
axios.get(path)
.then((response) => {
dispatch({type: "FETCH_PLACES_FULFILLED", payload: response.data})
})
.catch((err) => {
dispatch({type: "FETCH_PLACES_REJECTED", payload: err})
})
}
}
和我的减速器:我使用取从我的智能组件的数据
const reducer = (state={
places: [],
isFetching: false,
error: null
}, action) => {
switch(action.type) {
case "FETCH_PLACES" : {
return { ...state, isFetching: true }
}
case "FETCH_PLACES_REJECTED" : {
return { ...state, isFetching: false, error: action.payload }
}
case "FETCH_PLACES_FULFILLED" : {
return { ...state, isFetching: false, places: action.payload }
}
default:
return state
}
}
每个地方都有一个属性叫做good_for
,这是一个字符串数组。
我现在希望能够通过标记过滤地点(通过已经存在的查询字符串传递),但是我需要能够在从数据库中检索地点后直接进行此操作。
我该如何在“Redux方式”中进行整合?