为了账号安全,请及时绑定邮箱和手机立即绑定

redux的action怎么调用其他的reducer 的返回值

redux的action怎么调用其他的reducer 的返回值

繁星点点滴滴 2018-12-31 14:00:09
redux的action怎么调用其他的reducer 的返回值
查看完整描述

1 回答

?
RISEBY

TA贡献1856条经验 获得超5个赞

在todo例子中,按照官方文档把state拆分成todos和visibility,现在我在另一个reducer中需要用到todos,比如设置所有的todos的completed为true(false),这个具体要怎么做?
以下是代码

function todos(state = initialState, action) {
switch (action.type) {
case ADD_TODO:
return [
...state,
{
text: action.text,
competed: false
}
];
default:
return state;
}}

function allCompleted(state, action) {
switch (action.type) {
case YES:
return xxxx;//这里要怎么实现,才能引用到或者共享上面的todos,因为要遍历所有todo的completed属性,
default:
return state;
}
}
解决方案1:
新加两个action,然后把allComleted函数放在todos函数里面,操作同一个state下的todos树


查看完整回答
反对 回复 2019-01-06
  • 1 回答
  • 0 关注
  • 1459 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信