I need to call React function (this.clearMath()) from JQ function
$('.input-content').focus(
function(){
this.clearMath()
})
I got Uncaught TypeError: this.clearMath is not a function. I think it´s caused by JQ that thinks this.
is reference to selected element $('.input-content')
.
Am I right? And how to distinguish between react this
an jquery this
to be able call my function? Thanks
I need to call React function (this.clearMath()) from JQ function
$('.input-content').focus(
function(){
this.clearMath()
})
I got Uncaught TypeError: this.clearMath is not a function. I think it´s caused by JQ that thinks this.
is reference to selected element $('.input-content')
.
Am I right? And how to distinguish between react this
an jquery this
to be able call my function? Thanks
-
this
makes reference to the scope where you currently are. In this case, you are right, the scope is of the selector. I'm not sure why are you trying to call a React function from jQuery. That doesn't seems right. As far as I'm concerned, it is not possible to call a React function defined inside a React ponent from jQuery. – juanecabellob Commented Feb 16, 2017 at 13:56 - Can you post your code in a jsfiddle for better understanding what you are trying to do? – juanecabellob Commented Feb 16, 2017 at 13:59
1 Answer
Reset to default 8You can solve this by doing this:
var _ = this;
$('.input-content').focus(
function(){
//this is still the input
_.clearMath()
})
So you save the this context before the selector so you can access the _ inside the function, its called a closure.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744255293a4565367.html
评论列表(0条)