Jquery 延迟两个数组 Backbone
Jquery Deffered Two Arrays Backbone
早上好,
我好像碰壁了,问题是我希望在我的页面完成 GET 和 POST 请求后触发弹出窗口,因为弹出窗口中的数据需要正确。
无论如何,我已经尝试使用不同的对象和两个推送的项目,但这仍然不起作用,弹出窗口在几秒钟后被触发。在网络选项卡中,仍有许多请求仍在触发。任何帮助都会得到应用。
var promises = [];
_.each(models, _.bind(function (item) {
var filter = this.resources.get(item.id);
promises.push(filter.fetch(
{
success: function (model, response) {
var user = new UserModel();
promises.push(user.save());
}
}));
}, this));
$.when.apply($, promises1).then(_.bind(function () {
var popupForm = new PopUpView();
this.$el.append(popupForm.$el);
}, this));
您似乎有错字:您将 promises1
传递给了 when()
,而不是 promises
。
旁注: _.each()
接受上下文作为第三个参数,无需显式使用 _.bind()
。
var promises = [];
_.each(models, function(item) {
var filter = this.resources.get(item.id);
promises.push(filter.fetch({
success: function(model, response) {
var user = new UserModel();
promises.push(user.save());
}
}));
}, this);
$.when.apply($, promises).then(_.bind(function() {
var popupForm = new PopUpView();
this.$el.append(popupForm.$el);
}, this));
早上好,
我好像碰壁了,问题是我希望在我的页面完成 GET 和 POST 请求后触发弹出窗口,因为弹出窗口中的数据需要正确。
无论如何,我已经尝试使用不同的对象和两个推送的项目,但这仍然不起作用,弹出窗口在几秒钟后被触发。在网络选项卡中,仍有许多请求仍在触发。任何帮助都会得到应用。
var promises = [];
_.each(models, _.bind(function (item) {
var filter = this.resources.get(item.id);
promises.push(filter.fetch(
{
success: function (model, response) {
var user = new UserModel();
promises.push(user.save());
}
}));
}, this));
$.when.apply($, promises1).then(_.bind(function () {
var popupForm = new PopUpView();
this.$el.append(popupForm.$el);
}, this));
您似乎有错字:您将 promises1
传递给了 when()
,而不是 promises
。
旁注: _.each()
接受上下文作为第三个参数,无需显式使用 _.bind()
。
var promises = [];
_.each(models, function(item) {
var filter = this.resources.get(item.id);
promises.push(filter.fetch({
success: function(model, response) {
var user = new UserModel();
promises.push(user.save());
}
}));
}, this);
$.when.apply($, promises).then(_.bind(function() {
var popupForm = new PopUpView();
this.$el.append(popupForm.$el);
}, this));