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();
}
答案 0 :(得分: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();
};