我有一个对象集合,需要将其传递给ngxs操作。我能够传递单个对象,并且它可以存储状态并且工作正常,但是我不想迭代该对象,而是想传递整个集合?
我尝试了单个对象的正常运行,但是想要传递整个集合吗?
我正在尝试这样,但是它不起作用:
export class AddAccounts {
static readonly type = '[Account] Add';
constructor(public payload: Account[]) { }
}
//this.accounts is a collection of Account[] type.
this.store.dispatch(this.accounts);
export class AccountStateModel {
accounts: Account[][];
}
@State<AccountStateModel>({
name: 'accounts',
defaults: {
accounts: []
}
})
@Selector()
static getAccounts(state: AccountStateModel) {
return state.accounts;
}
@Action(AddAccount)
add({ getState, patchState }: StateContext<AccountStateModel>, { payload }:
AddAccount) {
const state = getState();
patchState({
accounts: [...state.accounts, payload]
});
}
有没有办法将整个集合传递给动作?