2011-08-23 3 views
1

'value'는 5이고 'maxValue'는 39입니다. 진행률 막대 (wijmo progressbar)에 표시된 값은 5.07입니다. {0}은 백분율이 아닌 진행률 값을 표시하도록 진행률 표시 줄에 알려야합니다. 값을 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} 

업데이트

내가 progressChanging 이벤트 동안 값의 참조하지만, 애니메이션이 완료되면 라벨 표시 (5) 대신에 5.07을하는 방법을 잘 모르겠습니다 수 있습니까? 라이브 예제가 있습니다 here

답변

1

정수를 표시하려면 라운드해야합니다. JavaScript는 모든 항목에 대해 수레를 사용합니다.
How do I convert a float number to a whole number in JavaScript?

--- 내가 그 정확한 진행 표시 줄에 특히 익숙하지 오전하지만 그들은 모두 비슷 업데이트 ---
에 대한 응답.
무슨 일이 일어나는가는 변수가 초기화 될 때 한 번만 호출하고 변수가 업데이트되는 경우가 아니라는 것입니다.

완료 막대가 진행률 막대로 전달되기 전에 완성 된 개수를 반올림하려는 위치 인 로딩 막대와 관련된 이벤트가 있습니다.

무슨 일이 일어나고 있는지 잘 설명하고 있는지 확실하지 않습니다.
값 = Math.round (myobj.completedCount) --- 업데이트 이벤트 -> 완료 개수 = newValue
--- 업데이트 이벤트 ---> 완료 횟수 = newValue
당신이해야 할 일은 그 업데이트 이벤트를 잡아서 변수를 반올림하는 것입니다.
--- 업데이트 이벤트 -> completedCount = 라운드 (NEWVALUE)

------ 말썽 라인은 소스에서 대체 라인 (328)이
percent = (value - self.min)/(self.max - self.min) * 100;
입니다 본 -------
를 TRY wijmo 바의 코드는
percent = Math.round((value - self.min)/(self.max - self.min)) * 100;
이며 원하는대로 작동해야합니다.

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

나는 또한 wijmo 개발자와 bug 기록 : -

+0

은 내가 이미 시도 언급해야합니다. 차이는 없습니다. 코드를 업데이트했습니다. – codecowboy

+0

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

+0

다른 업데이트를했습니다. 부동 소수점 숫자는 어디에서 왔는지 알 수 있지만 변경 방법을 모르겠습니다. 내 완료 카운트 변수가 변경되지 않아서 무슨 뜻인지 잘 모르겠습니다. completedCount = round (newValue) – codecowboy

0

나는 (우웩 ProgressBar의 JS 파일을 편집) 결국이와 함께 갔다.

소스를 편집하지 않고 또 다른 옵션은 다음과 같습니다

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