Javascript 通行证;这";在承诺内?
我正在努力学习承诺 我的URL将包含三个ID参数,例如Javascript 通行证;这";在承诺内?,javascript,jquery,ajax,promise,Javascript,Jquery,Ajax,Promise,我正在努力学习承诺 我的URL将包含三个ID参数,例如 #org=123&num=145&denom=467 我想用它们来选择页面上三个select元素的值(每个元素都有一个Ajax源代码),例如 任何关于我这样做的其他建议也将被感激地接受 可以使用()/传递自定义执行上下文 setFormValues: function() { return _this.getOrgs() .then(_this.getNumerators.bind(_this)) //us
#org=123&num=145&denom=467
我想用它们来选择页面上三个select
元素的值(每个元素都有一个Ajax源代码),例如
任何关于我这样做的其他建议也将被感激地接受 可以使用()/传递自定义执行上下文
setFormValues: function() {
return _this.getOrgs()
.then(_this.getNumerators.bind(_this)) //using bind() - supported in IE9+
.then($.proxy(_this.getDenominators, _this)) //using $.proxy()
.then(function() {
return true;
}
});
}
或者可以使用ajax中的上下文选项传递自定义上下文
getOrgs: function() {
return $.ajax({
type: 'GET',
url:'/api/orgs/?q=' + this.globalOptions.orgId,
dataType: 'json',
context: this
});
},
你能提供更多关于如何使用这些函数的代码吗?可能是Brilliant的重复,谢谢-上下文:这个选项对我有效。
setFormValues: function() {
return _this.getOrgs()
.then(_this.getNumerators.bind(_this)) //using bind() - supported in IE9+
.then($.proxy(_this.getDenominators, _this)) //using $.proxy()
.then(function() {
return true;
}
});
}
getOrgs: function() {
return $.ajax({
type: 'GET',
url:'/api/orgs/?q=' + this.globalOptions.orgId,
dataType: 'json',
context: this
});
},