0
私はonClickイベントをいくつかのパラメータで実行しています。このparamtの現在のイベントに追加するには?私は、次のビュー(すべてではありませんnesseccaryコードが削除された)しました。このevent.stopPropagation()
転送イベントをonClickに返す
私のコードのような機能somethigでやりたい:
はimport React from 'react';
export default class AllCarWashTable extends React.Component{
constructor(props) {
super(props);
this.removeCarWashHandler = this.removeCarWashHandler.bind(this);
...
};
removeCarWashHandler(e, name, id){
e.stopPropagation();
...
}
generateRows() {
const removeCarWashHandler = this.removeCarWashHandler
...
return data.map(function(item) {
var cells = cols.map(function(colData) {
...
<button type="button"
onClick={()=> removeCarWashHandler(item['name'], item['id'])}>
ButtonName
</button>
...
});
}
}
Currenly私のコードが例外につながる:TypeError: Cannot read property 'stopPropagation' of undefined
は、どのようにこの問題を解決するために?あなたが関数にイベントを渡すのを忘れて
はい、あなたはabsolutly正しいです。ありがとうございました。 –
問題が解決したら、私の答えを正しいものとしてマークすることができます。 –