【发布时间】:2018-11-15 13:11:39
【问题描述】:
设置
在我的应用中,我有学生被分配了家庭作业。每次创建一个学生时,我都会遍历当前作业并更新每个学生的作业数组。
我的问题是当我创建作业。不仅要创建作业,而且我需要在创建后将其分配给特定的学生。
我已将我的应用程序拆分为三个减速器;班级、学生和家庭作业。
问题
如何从 Homework reducer 更新我的学生状态?我需要等到作业创建完成,然后为每个学生分配作业数组。或许我可以先发送一个操作,然后再发送另一个?
case actionTypes.CREATEHOMEWORKS:
// Get new homework description
const newHomework = action.newHomework
// Get the currently active class
const activeClass = action.activeClass.key;
// Get users current browser data
const dateCreated = getCurrentDate();
// Generare a new UID
const key = guid();
// Create a new homework object
const homework = { key: key, class: activeClass, dateCreated: dateCreated, description: newHomework };
// Get the current homework array
const homeworks = JSON.parse(JSON.stringify(state.homeworks));
// Combine current homework with new homework object.
homeworks.push(homework);
// I now need to update students to have this homework but they are handled
// in another state
【问题讨论】:
-
可以参考这个解释:jamesknelson.com/…
标签: javascript reactjs redux reducers