0
我主要负责整个转换资金的大对象。对象内回调值从一个方法到第二个
在这个对象内我有4种方法。
addTaxAndShowBack()
是我的“主要”方法,它以某种回调地狱的形式执行其他链接。
addTaxAndShowBack: function(priceField,selectedCurrency) {
var that = this;
var convertedToUSD = this.convertToUSD(priceField,selectedCurrency)
.then(function(response) {
console.log(response);
var priceInUSD = response;
that.addTax(priceInUSD,selectedCurrency)
.then(function (response) {
console.log(response); // !!! THIS CONSOLE.LOG DOESN'T LOG ANYTHING
}, function() {
console.log('error');
});
}, function (response) {
console.log(response);
});
},
首先执行的方法(convertedToUSD()
)工作正常返回转换资金从用户默认货币为美元。第二个是addTax()
,它没有返回值我想如何。 console.log(response)
不记录任何东西。 addTax
方法的代码是:
addTax: function(priceInUSD, selectedCurrency) {
var finalPriceInUSD;
if(priceInUSD<300){
// i should also store userPriceInUSD in some variable
// maybe rootScope to send it to backend
finalPriceInUSD = priceInUSD*1.05;
console.log('after tax 5%: '+finalPriceInUSD);
return finalPriceInUSD;
} else {
finalPriceInUSD = priceInUSD*1.03;
console.log('after tax 3%: '+finalPriceInUSD);
return finalPriceInUSD;
}
},
我可能做错事在addTax()
无法正常返回或不正确addTaxAndShowBack()
分配它,我不知道,这就是为什么我需要你的帮助。
return finalPriceInUSD;
这就是response
在addTaxAndShowBack()
中的第二个回调应该是。