如何将jQuery与React js集成?

时间:2016-08-30 15:21:49

标签: javascript jquery reactjs

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

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>
        )



    }

})

1 个答案:

答案 0 :(得分:1)

你有拼写错误newscontanier。尽管如此,你可以这样做

<div ref={elem => this.elem = elem} className="newscontanier" id="newscontanier">{newsdata}</div>

然后你就可以找到dom元素

this.elem.getDOMNode();