我正在尝试对数组ob对象调用操作。在上一个操作的onSuccess方法上调用该操作。在单个对象上调用操作时,我能够正确执行所有操作,但是当我在forEach或for循环中调用它时,它永远不会执行。
这是我的导入
import {createClient} from "../../store/actions/clients/clients.actions";
import {createNewContact} from "../../store/actions/contact-list/contact-list.actions";
这是我的连接装饰
@connect(
state => ({avatarURL: state.avatar.URL}),
dispatch => bindActionCreators({modalVisibility, updateAvatarURL, createClient, createNewContact}, dispatch)
)
这是我的两个动作叫做
this.props.createClient({
newClientData, onSuccess: (newClientData) => {
for (let contact of values.contacts) {
contact.clientId = newClientData.id;
this.props.createNewContact(contact);
}
this.props.modalVisibility(false);
}
});
这是我的行动
export const createNewContact = (params) => {
debugger
return dispatch => {
let user = {
email: params.email,
name: params.firstName,
surname: params.lastName,
password: params.password,
clientId: params.clientId
};
let onSuccess = () => {
dispatch({
type: actions.CREATE_CLIENT_SUCCESS,
payload: {...params.newClientData}
});
if (params.onSuccess) params.onSuccess({...params.newClientData});
};
let onFailure = () => {
dispatch({
type: actions.CREATE_CLIENT_FAILURE,
payload: error
});
if (params.onFailure) params.onFailure(error);
};
awsServices.createUserInTheGroup({...user, group: config.groups.clients}, onSuccess, onFailure);
};
};
提前感谢!