大佬教程收集整理的这篇文章主要介绍了jquery – 如何在一些Backbone保存后发出一个AJAX请求,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
BACkboneModel.save( {},{ wait: true,success: function (model1,response1) { $.each(BACkboneCollection1.models,function () { this.save( {},{ wait: true,success: function (model2,response2) { $.each(BACkboneCollection2.models,function () { this.save( {},{ wait: true,response2) { //If i put the AJAX request here it will happen for every iteration which is not desired } }); }); } }); }); //If i put the AJAX request here it will fire after one iteration of the first each even with async set to false on the AJAX request } });
有没有人对在哪里执行这个AJAX请求有任何建议,所以它只在所有骨干模型保存到服务器后触发一次?
大部分变更都是用上面的替换.
var saveEverything = BACkboneModel.save() .pipe(function() { return saveCollection(BACkboneCollection1); }) .pipe(function() { return saveCollection(BACkboneCollection2); }); saveEverything.done(function() { console.log('done with everything,ajax time') });//make your ajax call in the done
如果你不知道jQuery承诺是什么,this是一个非常好的博客文章解释承诺.如果我的例子根本没有任何意义,我可以尝试解释发生了什么以及发生了什么.
以上是大佬教程为你收集整理的jquery – 如何在一些Backbone保存后发出一个AJAX请求全部内容,希望文章能够帮你解决jquery – 如何在一些Backbone保存后发出一个AJAX请求所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。