Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript reactjs/flux:按顺序执行操作(ajax)_Javascript_Ajax_Reactjs_Flux - Fatal编程技术网

Javascript reactjs/flux:按顺序执行操作(ajax)

Javascript reactjs/flux:按顺序执行操作(ajax),javascript,ajax,reactjs,flux,Javascript,Ajax,Reactjs,Flux,我有一些flux操作,它们只是AJAX调用,用成功时的数据更新存储 在我的组件中,我有一个使用以下操作的函数: // Insert new event ReactActions.submitNewEvent(data) // Insert new exceptions ReactActions.submitNewExceptions(exception_objects) // Merge ReactActions.merge(data, exception_objects) 在执行第三个操

我有一些flux操作,它们只是AJAX调用,用成功时的数据更新存储

在我的组件中,我有一个使用以下操作的函数:

// Insert new event
ReactActions.submitNewEvent(data)
// Insert new exceptions 
ReactActions.submitNewExceptions(exception_objects)

// Merge
ReactActions.merge(data, exception_objects)
在执行第三个操作之前,我希望完全执行前两个操作(意味着ajax方法的200个成功响应)


在类似于流量的体系结构中,实现这一点的最佳方法是什么?我应该选择承诺吗?你能举个例子吗?

是的,承诺是解决此类问题的好方法

将帮助您将最后一次通话与前两次通话同步。确保
submitNewEvent()
submitNewExceptions()
都返回在AJAX调用完成时解决的承诺:

Promise.all([
    ReactActions.submitNewEvent(data),
    ReactActions.submitNewExceptions(exception_objects)
]).then(function() {
    ReactActions.merge(data, exception_objects)
})

非常感谢。那么,我的Action的ajax在返回时是否需要使用
Promise.resolve()
包装?请查看。他们给出了一些很好的例子来说明如何实现它们。