我的代码块如下:为什么我不能在这种方法中调用道具? (反应)
class Buerger extends React.Component {
constructor() {
super();
this.gehaltHandler = this.gehaltChange.bind(this)
}
render() {
return(
<div style={{textAlign:"right", marginTop:'-103', marginRight:'900px'}}>
<Anzeige stand = {"Bargeld: " + this.props.stand}/>
<Arbeit gehalt = {this.props.gehalt} gehaltChange = {this.gehaltChange} arbeitenFunc = {this.props.arbeitenFunc}/>
</div>
)
}
gehaltChange(inputWert) {
const test = this.props.gehalt
alert(test)
}
所以我通过道具“gehalt”从父类,你可以看到我再次把它传递给所谓的“Arbeit子类的子类“。
Funktion gehaltChange正在使用警报('click')进行检查,但通过此代码,我得到了“无法读取属性”的未定义属性。
gehalt到“Arbeit”的传递也在工作,因为我测试它作为一个按钮名称,它显示正确的值没有问题。
我不明白。有人看到我做错了什么?难道我不能通过以前通过的道具并同时使用它们吗?我会感谢任何帮助。
对不起,谢谢funktion正在工作,但我实际上没有通过绑定的功能作为一个名称更改解决它的道具。 => gehaltChange = {this.gehaltHandler} 尽快接受答案。 – OhLongJohnson