0

我有一个变量的问题,该变量没有在 promise 的回调函数中更新,如下面的代码块所示:

 $scope.showSelected= function (node){
                var promise = $http.get("http://127.0.0.1:5000/getResource?ldpr="+node.iri);
                promise.then(function(result){
                    node = result.data;
                });
        };

$scope.showSelected是小部件使用的回调。它有一个参数node,我试图在 promise 的回调中更新它。如何在承诺的回调中更新此变量

4

1 回答 1

1

return函数中没有值$scope.showSelectedreturn来自异步函数调用的值,用于.then()在返回 a 的异步调用完成时执行Promise任务

 $scope.showSelected = function (node){
                         return $http.get("http://127.0.0.1:5000/getResource?ldpr="+node.iri);
                       };

 $scope.showSelected(node)
 .then(function(result) {
   // do stuff with `result` : `node`
 })
 .catch(function(err) { // handle error
   console.log(err)
 })
于 2017-07-16T21:02:06.253 回答