javascript - Call react function from JQ function - Stack Overflow

I need to call React function (this.clearMath()) from JQ function$('.input-content').focus(fu

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

Share Improve this question asked Feb 16, 2017 at 13:48 M. FrydlM. Frydl 731 silver badge9 bronze badges 2
  • 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
Add a ment  | 

1 Answer 1

Reset to default 8

You 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

相关推荐

  • javascript - Call react function from JQ function - Stack Overflow

    I need to call React function (this.clearMath()) from JQ function$('.input-content').focus(fu

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信