我努力让自己在这样.MAP方法的每一个项目的onClick效果的内部状态:如何访问内部函数是函数内部地图
this.props.products.map(function(item, i) { return ( <tr key={ i } onClick={ function() { console.log(arrayForOnClick) arrayForOnClick = [item['id'], item['name'], item['price']] this.handleTableString(item['id'], item['name'], item['price']) // Нужно передать айди, имя и цену в модальное окно при клике на этот <tr>. } }> <td>{ item['id'] }</td> <td>{ item['name'] }</td> <td>{ item['price'] }</td> </tr> ) }, this)
我试图访问此。 handleTableString这是
handleTableString(id, name, price) { this.setState({ editProductModal: true, selectedId: id, selectedName: name, selectedPrice: price }) console.log('triggered') }
,但我得到的错误Uncaught TypeError: Cannot read property 'handleTableString' of null
是否有另一种方法,使的onClick什么是错我的代码?