简体   繁体   English

如何使用使用Reactjs修改DOM的jQuery插件?

[英]How to use jQuery plugin that modify the DOM with Reactjs?

I have a question following this post: 我在这篇文章之后有一个问题:

issue 问题

How should I use a jQuery plugin that modify the DOM with react. 我应该如何使用带有react修改DOM的jQuery插件。 Like jimfb kindly answered to me on GH, React shoud return a pre-rendered component. 就像jimfb在GH上对我的回答一样,React应该返回一个预渲染的组件。 So my question is, how exaclty call a function like remodal() in my example, during the lifecycle of a component? 所以我的问题是,在组件的生命周期中,如何在示例中调用像remodal()这样的函数?

I suggest you to read my answer here: Why should addChangeListener be in componentDidMount instead of componentWillMount? 我建议您在这里阅读我的答案: 为什么addChangeListener应该位于componentDidMount中而不是componentWillMount中?

But basically, when you need to integrate some existing plugin or code with React, the painless way is to generally call that code on the componentDidMount method and do the event listening the old way. 但是基本上,当您需要将一些现有的插件或代码与React集成在一起时,轻松的方法通常是在componentDidMount方法上调用该代码,并以旧的方式监听事件。 If you are with jQuery, that means you should use something like 如果您使用的是jQuery,则意味着您应该使用类似

$(this.getDOMNode()).find('.some-child').on('click', this.onChildClick)

By doing it this way, you will miss some of the most important features regarding event delegation in React (see https://facebook.github.io/react/docs/interactivity-and-dynamic-uis.html#under-the-hood-autobinding-and-event-delegation ) but that should not be a problem unless you wanted to create hundreds of event listeners. 通过这种方式,您将错过与React中的事件委托相关的一些最重要的功能(请参阅https://facebook.github.io/react/docs/interactivity-and-dynamic-uis.html#under-the- hood-autobinding-and-event-delegation ),但这应该不是问题,除非您想创建数百个事件侦听器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM