【发布时间】:2018-10-05 11:48:12
【问题描述】:
我在 react.js 中将 jqwidget 用于网格。我有 JqxListBox 在我的父组件中有一个选项列表。
class ParentComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
return <JqxListBox ref='myListBox' style={{ float: 'left' }} width={150} height={150} source={listBoxSource} checkboxes={true} />;
}
}
当用户在 jqxlistbox 中选择或取消选择某个选项时,我想在网格中打开显示和隐藏列,但在子组件中无法访问参考。如何在子组件 react 中访问 jqxlistbox 属性。在子 componentDidMount 函数中,我正在访问 ref 之类的。
class ChildComponent extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
// Cannot read property 'on' of undefined
this.refs.myListBox.on('checkChange', (event) => {
console.log("something");
});
}
render() {
return <div>Child component</div>;
}
}
它给了我错误:TypeError: Cannot read property 'on' of undefined
【问题讨论】:
-
你使用的是哪个版本的 React ?
-
@klugjo 我正在使用 react 16.3.2。
-
父子组件之间没有关系
标签: javascript reactjs jqwidget