admin管理员组文章数量:1400455
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.
本文标签: javascriptCall react function from JQ functionStack Overflow
版权声明:本文标题:javascript - Call react function from JQ function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744255292a2597449.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论