我有一种情况,我需要保存一个 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,
success: function (model2, 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 请求有任何建议,以便在所有主干模型保存到服务器后仅触发一次?