查看 jQuery 文档,我发现了以下内容:
$.get( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" ); <---
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
在进行几次 ajax 调用后,我需要在 Angular 控制器中执行一个方法,如下所示:
$q.all([
$http.get(ROOT + "Lookup/GetStates"),
$http.get(ROOT + "Lookup/GetCountries"),
$http.get(ROOT + "Address/GetAddresses"),
]).then(function (results) {
$scope.states = jQuery.parseJSON(results[0].data.data);
$scope.country = jQuery.parseJSON(results[1].data.data);
$scope.addresses = jQuery.parseJSON(results[3].data);
});
之后then
被处决(仅在then之后)我需要调用一个方法$scope.setupControls()
有这种可能吗?
为什么你不能这样做:
$q.all([
$http.get(ROOT + "Lookup/GetStates"),
$http.get(ROOT + "Lookup/GetCountries"),
$http.get(ROOT + "Address/GetAddresses"),
]).then(function (results) {
$scope.states = jQuery.parseJSON(results[0].data.data);
$scope.country = jQuery.parseJSON(results[1].data.data);
$scope.addresses = jQuery.parseJSON(results[2].data);
$scope.setupControls();
});
我认为没有必要再取得第二次成功。保持简单(并且性感?)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)