0

buildMyUrl 的结果在调用函数中始终未定义。我不确定链接这些函数我做错了什么:

var buildMyUrl = function (callback)
{   
    var param;

    var addParams = function (domainUrl)
    {
        domainUrl += "page.aspx?";
        domainUrl += "Param1=";
    };

    $.when(self.buildDomainUrl()).then(addParams);
};

buildDomainUrl返回一个 JQuery 承诺并添加参数工作正常。现在我有一个想要使用结果的函数buildMyUrl

    var buildAPageUrl  = function ()
    {
        var dfd = $.Deferred();

        var addCalendarPage = function (domainUrl)
        {
             dfd.resolve(domainUrl += "/Calendar.aspx?");
        };

   // Here lies the problem (buildMyUrl is undefined)
        $.when(buildMyUrl()).then(addCalendarPage);

        return dfd.promise();
    }
4

1 回答 1

0

以下作品基于 Kevin B 的评论:

var buildMyUrl = function (callback)
{   
    var dfd = $.Deferred();
    var param;

    var addParams = function (domainUrl)
    {
        domainUrl += "page.aspx?";
        domainUrl += "Param1=";
        dfd.resolve();
    };

    $.when(self.buildDomainUrl()).then(addParams);
    return dfd.promise();
};
于 2012-05-18T09:39:41.780 回答