私は反応するために新しいです、私はちょうど様々なdivsのためのビューカウンタを作っています。私はdivとscrollTopの高さの高さが必要です。しかし、値を取得した後、私は値をsetstateする必要があります。あなたはちょうどここに構文エラーがありcomponentDidMountが自分の状態を更新していませんか?
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"
}, ],
length: null,
height: 0
}
},
componentWillMount: function() {},
componentDidMount: function() {
console.log(this.state.length)
var lengthh = document.getElementById('newscontanier').children.length;
console.log(lengthh);
if(lengthh != this.state.length) {
this.setState({
length: lengthh //Still null
})
}
},
render: function() {
var newsdata = this.state.news.map(function(newss) {
return(< NewsDetail key = {
newss.id
} {...newss
}
/>)
});
return(<div className="newscontanier" id="newscontanier">{newsdata}</div>)
}
})
を私はあなたの変数の命名上のビットを学ぶお勧めします。あなたのコードを見ると、何が起こっているのか、何かが誤植であるのか意図的であるのかを知ることは非常に難しい**です。 –
申し訳ありません私はプログラミングに慣れていません。実際にはdivを正しく表示します。しかし、状態は更新されていません。 – Nane
'lengthh!= this.state.length'条件が成り立つかどうかチェックしましたか? 'nullh == undefined // true'を使用している場合)条件を使用して' setState'が呼び出されることはありません – Igorsvee