首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将jQuery与React js集成?

如何将jQuery与React js集成?
EN

Stack Overflow用户
提问于 2016-08-30 23:21:49
回答 1查看 202关注 0票数 0

我非常需要jQuery api的api,但问题是我已经在React js中使用了这个api。我只是混淆了我的React js生命周期。附加信息我正在为不同的div创建视图计数器。在我看来,我非常需要jQuery的api来照顾高度,ScrollTop..下面的代码将输出Undefined

代码语言:javascript
复制
var React = require('react');
var ReactDOM = require('react-dom');
var NewsDetail = require('./news-details');
var $ = require('jquery');


module.exports = React.createClass({
    getInitialState:function () {

      return{
          news:[
              {

              {
                  id:"5",
                  data:"I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
              },
              {
                  id:"6",
                  data:"I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
              },
              {
                  id:"7",
                  data:"I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
              },
              {
                  id:"8",
                  data:"I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
              },
              {
                  id:"9",
                  data:"I probably am using the wrong I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value I probably am using the wrong terminology here but this is what I'm trying to do. I want to create a map with a value terminology here but this is what I'm trying to do. I want to create a map with a value for each key and a value for each key's object. S"
              },

          ],
          top:0,
          height:null
      }
    },
    componentWillMount:function () {

    },
    componentDidUpdate:function () {

        var height = $('#newscontainer').height();
        alert(height)//udefined

    },
    render:function () {

      var newsdata = this.state.news.map(function (newss) {

          return(<NewsDetail key={newss.id} {...newss}/>)
      });
        return(
            <div className="newscontanier" id="newscontanier">{newsdata}</div>
        )



    }

})
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-30 23:34:43

你有拼写错误的newscontanier。不过,您可以这样做

代码语言:javascript
复制
<div ref={elem => this.elem = elem} className="newscontanier" id="newscontanier">{newsdata}</div>

然后,您可以找到dom元素。

代码语言:javascript
复制
this.elem.getDOMNode();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39231457

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档