2014-03-27 189 views
-1

我試圖增加觀察的變量有1個,但它不能正確處理增量淘汰賽觀察到

的JavaScript:

self.fiscalYear = ko.observable(0); 
    self.fiscalStartYear = ko.observable(0); 
    self.fiscalEndYear = ko.observable(0); 

    self.showYearsDetail = function() { 
     self.fiscalStartYear(self.fiscalYear()); 
     self.fiscalEndYear(self.fiscalYear() + 1); 
    }; 

    self.fiscalYear.subscribe(function() { 
     self.showYearsDetail(); 
    }); 

HTML:

<div class="row-fluid"> 
     <div class="span2 display-label">Fiscal Year </div> 
     <input id="fiscalYear" type="text" data-bind="value: fiscalYear" placeholder="Fiscal Year"> 
    </div> 
    <div class="row-fluid"> 
     <div class="span2 display-label">Start Year </div> 
     <div class="span6 text-info"><span data-bind="text: fiscalStartYear"></span></div> 
    </div> 
    <div class="row-fluid"> 
     <div class="span2 display-label">End Year </div> 
     <div class="span6 text-info"><span data-bind="text: fiscalEndYear"></span></div> 
    </div> 

如果我插入2014

輸出開始年:2014 結束年份:20145

回答

5

嘗試更換此:

self.fiscalEndYear(self.fiscalYear() + 1); 

與此:

self.fiscalEndYear(parseInt(self.fiscalYear()) + 1); 
+1

其正常工作,謝謝你救我一命 –

+0

是否有一個原子的方法來做到這一點? –