2011-08-23 92 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); 
} 
})();