我们可以使用类似以下代码的方式将引用数组分配给不同的输入,例如:
<Progressbar completed={25} id="Progress1" ref={(input) => {this.Progress[0] = input }}/> <Progressbar completed={50} id="Progress2" ref={(input) => {this.Progress[1] = input }}/> <Progressbar completed={75} id="Progress3" ref={(input) => {this.Progress[2] = input }}/>
但是当我尝试它时,它返回此错误:
Uncaught TypeError: Cannot set property '0' of undefined
而且它不起作用,我是否缺少某些东西?
在构造函数中创建数组,例如:
constructor(){ super() this.Progress = [] }