我有模型Language
,Entities
,EntitiesInfo
export interface Language
{
name:string;
status:string;
id:number;
}
export interface Entities {
languages?:Language[];
}
export interface EntitiesInfo {
language?:Language;
}
以下是我的addEntityAction
export const ADD_ENTITY = 'Add Entity';
export interface AddEntityAction extends Action {
entity:string;
data:EntitiesInfo;
}
export const addEntity:ActionCreator<AddEntityAction> = (entity:string,data:EntitiesInfo):AddEntityAction => {
return {
type:ADD_ENTITY,
entity:entity,
data:data
}
}
这是我的州和减速机:
export interface EntityState {
entitiesList:Entities;
entitiesInfo?:EntitiesInfo;
}
const initialState:EntityState = {
entitiesList:null,
entitiesInfo:null
}
export const EntityReducer = function (state:EntityState = initialState,action:Action):EntityState{
switch(action.type)
{
case EntityActions.ADD_ENTITY:
const infoAdd = (<EntityActions.AddEntityAction>action);
switch(infoAdd.entity)
{
case "language":
state.entitiesList.languages = state.entitiesList.languages.concat(infoAdd.data.language);//this not working
return {entitiesList:state.entitiesList};
}
default:
return state;
}
}
我的示例发送:
this.entity = ["language":{"id":100,"name":"English","status":"Active"}]
this.store.dispatch(EntityActions.addEntity("language",this.entity))
我的getState()
语言英语不会合并到state.entitiesList.languages
数组中。