Dva: 关于在effect下用select获取当前model里state数据问题

Created on 19 Jan 2018  ·  5Comments  ·  Source: dvajs/dva

为什么在effect里用select获取当前model里state数据浏览器端直接报select not defined 问题!!!为什么呐

put 和call 都是正常的~~~~

Most helpful comment

@Cslove 需要这么写:

*addPost({payload}, {call, put, select}){
    ...
   const pay = yield select((state)=> ({domainId: state.modelName.stateKey})); 
   ...
}

你的代码里有两个错:
1、没有解构出 select 方法,
2、select 回调里的 state 是 redux 的state 对象,如果你想获取当前model 的需要 state.currentModelName
参考文档

All 5 comments

@Cslove 你贴下代码呢

_20180119113653
_20180119114302

@Cslove 需要这么写:

*addPost({payload}, {call, put, select}){
    ...
   const pay = yield select((state)=> ({domainId: state.modelName.stateKey})); 
   ...
}

你的代码里有两个错:
1、没有解构出 select 方法,
2、select 回调里的 state 是 redux 的state 对象,如果你想获取当前model 的需要 state.currentModelName
参考文档

额哈。。。也是忘了引入select,谢谢哈

select返回值做修改后会直接改state状态?为啥我的就直接改变了state了?

const roles = yield select(state =>state.organization.roles);
console.log(roles);
roles.forEach(function(curr,index,arr){
    if(curr.id==payload.selectKey){
        curr.action_list = payload.actionList.join();
     }
})
return true;
Was this page helpful?
0 / 5 - 0 ratings