2016-08-30 3 views
0

Мне очень нужен jQuery Api, но дело в том, что я использую api с React js. Я просто запутываю свой React js Lifecycles. Дополнительная информация Я создаю счетчик просмотров для разных div. В моей точки зрения я очень нужен JQuery API, чтобы заботиться высоту, ScrollTop .. Следующий код выведет НеопределенноеКак интегрировать jQuery с React js?

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



    } 

}) 
+2

Зачем вам нужен JQuery? Если вы просто получаете высоту элемента, вы можете сделать это без jQuery. –

+1

var height = $ ('# newscontainer'). Height(); выбирает неправильный идентификатор, согласно вашему DOM. ... id = "newscontanier" –

+0

Ваш идентификатор ошибочно написан в вашей функции рендеринга. – ray

ответ

1

Вы опечатка newscontanier. Тем не менее вы можете сделать это, как

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

, а затем вы можете найти дом элемент

this.elem.getDOMNode(); 
+0

getDOMNode [устарело] (https: //facebook.github.io/react/blog/2015/10/07/react-v0.14.html#dom-node-refs) – ray

+0

@ray Я этого не знал. в любом случае вы можете получить узел DOM из 'this.elem' –

Смежные вопросы