本文介绍了将参数传递给promisejs $ q中的promise成功回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这是一个与此非常相似的问题。但在我的情况下,我仍然不清楚如何做到这一点。只需要一些成功回调的帮助。

I realize this is a very similar question to this one. But I'm still unclear on how to do it in my situation. Just need some help with a successful callback.

这是有效的:

function getStuff(accountNumber) {
    var logMessage = 'POST GetStuff';

    return $http.post(GetStuff, { custId: accountNumber })
        .then(log);
}

function log(response) {
    logger.debug(response);
    return response;
}

这就是我想要完成的事情:

This is what I want to accomplish:

function getStuff(accountNumber) {
    var logMessage = 'POST GetStuff';

    return $http.post(GetStuff, { custId: accountNumber })
        .then(log(response, logMessage);
}

function log(response, logMessage) {
    logger.debug(logMessage, response);
    return response;
}


推荐答案

您可以使用:

function getStuff(accountNumber) {
    var logMessage = 'POST GetStuff';

    return $http.post(GetStuff, { custId: accountNumber })
        .then(
           function success(response) {
               return log(response, logMessage);
           }
        );
}

这篇关于将参数传递给promisejs $ q中的promise成功回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 22:07