这是我的代码:淘汰赛计算不点火订阅
self.convertedPrice = ko.computed(function() {
console.debug('Calculating convertedPrice');
if (self.ProductListPrice() != null && self.multiplicationFactor() != null) {
return self.ProductListPrice() * self.multiplicationFactor();
}
return 0;
}).extend({notify:'always'});
self.convertedPrice.subscribe(function (newVal) {
console.debug('convertedPrice subscription fired.');
self.discountedPrice(parseFloat(newVal).toFixed(2));
});
当self.ProductListPrice
更新,self.convertedPrice
正确地更新和调试第一写入,但认购不烧成,第二调试语句不会被写入和self.discountedPrice
未更新。
我已经通过将订阅的内容移动到计算的代码中来解决这个问题,但我想了解原始订阅无法工作的原因。如果我手动更改self.ProductListPrice
或self.multiplicationFactor
,订阅就会触发,但是当它们因我的其他代码和用户输入而更改时,订阅不会触发。
任何想法我做错了什么?
如果你想订阅计算何时启计算稍稍柚木它计算。使用'deferEvaluation:true' sample here http://jsfiddle.net/LkqTU/26144/ –
我已经尝试推迟评估,同时试图自己跟踪这个,但它没有任何区别。谢谢你的想法。 – Tim