2017-09-14 159 views
0

我正在使用office 365 progress bar。我从websocket获取数据(百分比)。现在我有下一个代码:为什么进度条总是显示100%?

export default class NotificationBar extends Component { 

    constructor(props) { 
     super(props); 
     this._async = new Async(this); 
    } 

    render(){ 
     let { process } = this.props;// this object I get from flux store, it refreshes when web socket updates 

     return (
        <ProgressIndicator 
         percentComplete={ this._getProgress() } /> 
     ) 
    }; 

    _getProgress =() => { 
     let { process } = this.props;//here this.props.process.percent updates 
     return process.percent; 
    }; 
} 

页面加载进度条变成100%后并没有改变,虽然我从方法得到百分比。我试图实验,并把在组件的渲染:

  • PERCENTCOMPLETE = {0} -progressbar是空
  • PERCENTCOMPLETE = {任何数量> 0}进度显示100%

什么可以是这种行为的原因?我犯了什么错误?

+0

你说有一个'this.props.percent',但你要返回'this.props.process.percent'。哪一个? :) – Chris

+0

有一个错误。它必须是this.props.process.percent.all已更正 –

+0

PercentComplete是否在0和1之间? –

回答

1

这是因为percentComplete必须是介于0和1之间的数字。如果您使用多于1,它会计为100%。

在编程中这种行为被广泛使用,因为50%只是50/100 = 0.5,例如。