我正在尝试将一个对象分配给另一个具有相同类型的对象。
所以,我有这个对象'语言'
export class Language {
languageDescription: string;
languageCode: string;
isDefault: boolean;
}
我声明了两个对象和selectedLanguage
语言类型:childSelectedLanguage
@State<LanguageSelectorStateModel>({
name: 'languageSelector',
defaults: {
languages: [],
selectedLanguage: null,
childSelectedLanguage: null
}
})*
填充 selectedLanguage 后(不再为空),
@Action(UpdateSelectedLanguage)
@ImmutableContext()
updateSelectedLanguage({ getState, patchState }: StateContext<LanguageSelectorStateModel>, { languageCode }: UpdateSelectedLanguage) {
const state = getState();
const selectedLanguage = state.languages.find(language => language.languageCode === languageCode);
state.selectedLanguage = selectedLanguage;
patchState(state);
}
我试图将此值的相同内容分配给 childSelectedLanguage。
childSelectedLanguage = selectedLanguage;
但是 childSlectedLanguage 仍然为空,尽管 selectedLanguage 不是。
我也试过
@Action(InitializeChildrenSelectedLanguage)
initializeChildrenSelectedLanguage(
{ getState, patchState }: StateContext<LanguageSelectorStateModel>,
{ }: InitializeChildrenSelectedLanguage
) {
const state = getState();
Object.assign(state.childSelectedLanguage, state.selectedLanguage);
patchState(state);
}
但我也无法将对象分配给内容。
第一个问题:为什么我不能分配对象?
第二个问题:我该如何解决这个问题?