I'm rendering a link with react:
render: ->
`<a className="upvotes" onClick={this.upvote}>upvote</a>`
Then, above I have the upvote function:
upvote: ->
// do stuff (ajax)
Before link I had span in that place but I need to switch to link and here's the trouble - every time I click on .upvotes
the page gets refreshed, what I've tried so far:
event.preventDefault() - not working.
upvote: (e) ->
e.preventDefault()
// do stuff (ajax)
event.stopPropagation() - not working.
upvote: (e) ->
e.stopPropagation()
// do stuff (ajax)
return false - not working.
upvote: (e) ->
// do stuff (ajax)
return false
I've also tried all of the above using jQuery in my index.html, but nothing seems to work. What should I do here and what I'm doing wrong? I've checked event.type and it's click
so I guess I should be able to avoid redirect somehow?
Excuse me, I'm a rookie when it comes to React.
Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…