Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的进度条显示浮点值?_Javascript_Jquery Ui_Wijmo - Fatal编程技术网

Javascript 为什么我的进度条显示浮点值?

Javascript 为什么我的进度条显示浮点值?,javascript,jquery-ui,wijmo,Javascript,Jquery Ui,Wijmo,本例中的“值”为5,“最大值”为39。进度条(a)上显示的值为5.07。{0}应该告诉progressbar显示进度值而不是百分比。如果将该值更改为8,将最大值保持为39,则显示的值将变为8.19。我有点困惑,为什么我看到的是浮点数而不是整数。在progressbar代码中,除了self.value()以整数形式登录控制台外,我看不到任何显示其他内容的内容。那么,是什么导致了这种行为呢 $("#proBarAdherence").wijprogressbar({ value: Gymloo

本例中的“值”为5,“最大值”为39。进度条(a)上显示的值为5.07。{0}应该告诉progressbar显示进度值而不是百分比。如果将该值更改为8,将最大值保持为39,则显示的值将变为8.19。我有点困惑,为什么我看到的是浮点数而不是整数。在progressbar代码中,除了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}
更新


我可以在ProgressChanged事件中看到值,但不确定动画完成后如何使标签显示5而不是5.07?有一个活生生的例子

如果你想显示整数,你需要舍入JavaScript使用浮点数

---对更新的响应---
我不是特别熟悉那个确切的进度条,但它们都很相似
发生的情况是,在初始化变量时,而不是在更新变量时,您只调用一次四舍五入。

有一个与正在更新的加载条相关的事件,您希望在将已完成的计数传递到进度条之前对其进行四舍五入

我不确定我是否能很好地解释发生了什么
value=Math.round(myobj.completedCount),--update event-->completedCount=newValue
--更新事件-->completedCount=newValue
你需要做的是捕捉更新事件并在那里对变量进行取整
---更新事件-->已完成计数=四舍五入(newValue)

------试试这个----
问题是这个
百分比=(value-self.min)/(self.max-self.min)*100

将wijmo条源代码中的第328行替换为
percent=Math.round((value-self.min)/(self.max-self.min))*100
并且它应该按照您希望的方式运行。

如果您想显示整数,则需要舍入JavaScript对所有内容都使用浮点数

---对更新的响应---
我不是特别熟悉那个确切的进度条,但它们都很相似
发生的情况是,在初始化变量时,而不是在更新变量时,您只调用一次四舍五入。

有一个与正在更新的加载条相关的事件,您希望在将已完成的计数传递到进度条之前对其进行四舍五入

我不确定我是否能很好地解释发生了什么
value=Math.round(myobj.completedCount),--update event-->completedCount=newValue
--更新事件-->completedCount=newValue
你需要做的是捕捉更新事件并在那里对变量进行取整
---更新事件-->已完成计数=四舍五入(newValue)

------试试这个----
问题是这个
百分比=(value-self.min)/(self.max-self.min)*100

将wijmo条源代码中的第328行替换为
percent=Math.round((value-self.min)/(self.max-self.min))*100
并且它应该按照您希望的方式运行。

最后我还是这样做了(编辑progressbar js文件-恶心):

我还与wijmo开发人员进行了交流

不编辑源的另一个选项是:

(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 );
}
})();

最后我还是这样做了(编辑progressbar js文件-恶心):

我还与wijmo开发人员进行了交流

不编辑源的另一个选项是:

(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 );
}
})();

应该说我已经试过了。这没什么区别。我更新了代码。我又做了一次更新。我现在可以看到浮点数的来源,但不确定如何更改它们。我的completed count变量没有更改,所以我不确定completed count=round(newValue)是什么意思。很抱歉,我帮不上什么忙。我通读了它的来源,不确定你的问题是什么,所以我担心我可能会让你更加困惑。只要你保持这个比率,即使它会保持一个整数,我也应该提到我已经尝试过了。这没什么区别。我更新了代码。我又做了一次更新。我现在可以看到浮点数的来源,但不确定如何更改它们。我的completed count变量没有更改,所以我不确定completed count=round(newValue)是什么意思。很抱歉,我帮不上什么忙。我通读了它的来源,不确定你的问题是什么,所以我担心我可能会让你更加困惑。只要你保持这个比率,它甚至会保持整数