2011-08-23 31 views
1

本例中'值'爲5,'maxValue'爲39.顯示在進度條(a wijmo progressbar)上的值爲5.07。 {0}應該告訴進度條顯示進度值而不是百分比。如果將該值更改爲8,則將最大值保持爲39,則顯示的值將變爲8.19。我有點困惑,爲什麼我看到浮點數而不是整數。我看不到進度條代碼中的任何內容,它將顯示除self.value()之外的任何東西,它們以整數形式記錄到控制檯。那麼可能會導致這種行爲?爲什麼我的進度條顯示浮點值?

$("#proBarAdherence").wijprogressbar({ 

    value: Gymloop.completedCount, 
    animationOptions: { 
    duration: 1000 
    }, 

    maxValue: Gymloop.targetSessions, 
    indicatorImage: '/images/progbar_red.png', 
    labelAlign: 'running', 
    labelFormatString: '{0} sessions completed', 
    beforeProgressChanging: function(e,data) { 
    console.log('beforeprogresschanging',data); 
    }, 
    progressChanging: function (e,data) { 
    console.log('progresschanging',data); 

    }, 
    progressChanged : function (e,data) { 
    console.log('progresschanged',data); 
    } 
}); 

beforeprogresschanging Object { oldValue="5", newValue=5} 
progresschanging Object { oldValue="5", newValue=0} 
progresschanging Object { oldValue="0", newValue=1.17} 
progresschanging Object { oldValue="1.17", newValue=1.56} 
progresschanging Object { oldValue="1.56", newValue=1.95} 
progresschanging Object { oldValue="1.95", newValue=2.34} 
progresschanging Object { oldValue="2.34", newValue=2.73} 
progresschanging Object { oldValue="2.73", newValue=3.12} 
progresschanging Object { oldValue="3.12", newValue=3.51} 
progresschanging Object { oldValue="3.51", newValue=3.9} 
progresschanging Object { oldValue="3.9", newValue=4.29} 
progresschanging Object { oldValue="4.29", newValue=4.68} 
progresschanging Object { oldValue="4.68", newValue=5.07} 
progresschanged Object { oldValue="5", newValue=5} 

更新

我可以progressChanging事件中看到了價值的,但我不知道如何使標籤顯示5,而不是5.07一旦動畫完成?有一個生動的例子here

回答

1

如果你想顯示整數你需要舍入JavaScript對所有東西都使用浮點數。
How do I convert a float number to a whole number in JavaScript?

---響應更新---
我不是特別熟悉,準確的進度條,但他們都是相似的。
發生什麼情況是變量初始化時調用一次,而不是變量更新時調用一次。

存在一個與正在更新的加載欄關聯的事件,這是您要將完成的計數舍入到傳遞到進度欄之前的位置。

我不確定我是否做得很好,解釋發生了什麼
value = Math.round(myobj.completedCount),---更新事件 - > completedCount = newValue
---更新事件---> completedCount = newValue
你需要做的是捕捉那個更新事件並且在那裏圍繞變量。
---更新事件 - > completedCount = ROUND(newValue)以

------嘗試此-------
麻煩的線是本
percent = (value - self.min)/(self.max - self.min) * 100;
更換線328從源wijmo欄的代碼與
percent = Math.round((value - self.min)/(self.max - self.min)) * 100;
它應該按照您希望的方式進行操作。

+0

應該提到,我已經試過了。它沒有任何區別。我更新了代碼。 – codecowboy

+0

http://wijmo.com/wiki/index.php/Progressbar#Events – Prospero

+0

我做了另一個更新。現在我可以看到浮點數的來源,但不知道如何改變它們。我完成的計數變量不會改變,所以我不確定你的意思是completedCount = round(newValue) – codecowboy

0

我這個在去年底(編輯進度的js文件 - 呸):

self.label.html(self._getFormatString(
      o.labelFormatString, Math.round(percent), Math.round(curValue))); 

我也記錄與wijmo開發商bug

,而無需編輯源的另一個選擇是:

(function(){ 
// Store a reference to the original html method. 
var originalHtmlMethod = jQuery.fn.html; 

// Define overriding method 
jQuery.fn.html = function(){ 

// Execute our override - rounding the value 
// being passed to jQuery's html() function 
// only when the progressbar label is being 
// updated 
if ($(this).hasClass('ui-progressbar-label')) { 
arguments[0] = Math.round(arguments[0]); 
} 

// Execute the original jquery method for all other html() calls on the  page 
originalHtmlMethod.apply(this, arguments); 
} 
})();