【发布时间】:2018-06-10 20:16:24
【问题描述】:
我在标题组件下拉列表中的行为类似于整个应用程序的过滤器。假设我的布局中有网格组件,其中填充了一些数据,例如某年可用的汽车列表。当我从标题年份的下拉列表中选择时,我想更新我的网格组件以仅包含选定年份可用的汽车。
这是我的减速器,带有动作创建器,用于标题组件中的下拉菜单。为简洁起见,我删除了一些代码。
export interface IImporterSelectorContextState {
dataQuery?: ServiceApi.IDataQuery;
data?: any[];
context?: ServiceApi.IDocumentContext
}
type KnownAction =
IChangeCurrentContext
export const actionCreators = {
changeYearContext: (context: ServiceApi.IDocumentContext) : AppThunkAction<KnownAction> => (dispatch, getState) => {
dispatch(changeCurrentContext(context));
}
}
const unloadedState: IImporterSelectorContextState = {
//removed for brevity
};
export const reducer: Reducer<IImporterSelectorContextState> = (state: IImporterSelectorContextState,
incomingAction: Action) => {
const action = incomingAction as KnownAction;
switch (action.type) {
case CHANGE_CURRENT_CONTEXT:
return {
...state,
context: action.context
}
default:
const exhaustiveCheck: never = action;
}
return state || unloadedState;
}
When year is selected, changeYearContext function is called, my state is set to new values for header component.我不确切知道如何更新显示汽车的网格组件。要根据我的过滤器获取新数据,我必须发送新请求(获取按钮)以获取新数据,但我想在选择下拉菜单时刷新数据。我怎样才能做到这一点?
【问题讨论】: