Home >Backend Development >PHP Tutorial >javascript - React es6 binding event problem

javascript - React es6 binding event problem

WBOY
WBOYOriginal
2016-07-06 13:52:551401browse

javascript - React es6 binding event problem
Using react redux to do a project, I encountered an event binding problem. Loop is a traversal method, such as loop (ajaxdata),

javascript - React es6 binding event problem

But I can’t get the id of this item, please help

Reply content:

javascript - React es6 binding event problem
Using react redux to do a project, I encountered an event binding problem. Loop is a traversal method, such as loop (ajaxdata),

javascript - React es6 binding event problem

But I can’t get the id of this item, please help

<code>onClick={() => {alert(item.id)}}</code>

The item in

onClick should be the parameter in the function declaration, not the actual parameter passed in. As a result, the item.id in the function body is actually the member value of the parameter. Remove the item parameter or change it to a variable other than item. Try
It is recommended to learn more about arrow functions

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn