I'm new to reactjs, I have stuck in between please help me out here :
I have a class component in react js. And I have <ul></li></li></ul>, here I'm adding <li> from jquery after some DB query. Now how can I add onClick event to li ? bcz when I'm adding it from jquery i.e it's giving 'undefined function this.getValue' in react js.
Here is below example :
class getData extends React.Component {
constructor(props) {
super(props);
}
getValue(p1,p2,p3) {
....
}
render() {
var dropdown = <ul id="dropD"></ul>
return (
{dropdown}
)
}
}
Now from Jquery, I'm get li with some DB query and appending it to ul as below
<li onClick=this.getValue('x','xx','xxx')>value 1</li>
<li onClick=this.getValue('x','xx','xxx')>value 2</li>
<li onClick=this.getValue('x','xx','xxx')> ... </li>
Here I'm getting all the dropdown properly, but when I click on dropdown (li) tag, I'm getting as 'undefined this.getValue function' because I'm adding it dynamically. If I hard code the li under ul, it is able to recognize the function and is working properly, only issue when I add li dynamically.
Please let me know if I add li tag dynamically then how can I call onClick function inside class component
onClickthis that, add this:onClick={this.getValue.bind(this,'x','xx','xxx')}, it should work.<li>s declaratively inside your React component class.