[英]how to access state value right after setting the same state variable in another function in react.js class component
[英]How to access variable in React.js component class
如果我有
const stateData = [
{
'id': 'AL',
'name': 'Alabama',
'capital': 'Montgomery',
'date': 'December 14, 1819'
},
{
'id': 'AK',
'name': 'Alaska',
'capital': 'Juneau',
'date': 'January 3, 1959'
}];
const SearchBarAndResults = React.createClass({
render() {
// QUESTION: how do I access variable stateData here and replace field
// from 'id': 'AL' to 'id': 'AK'?
}
});
您应该像本例一样将const stateData传递到您的组件中,然后您可以使用组件中的{this.props.data}来访问组件范围数据。
React.render(<SearchBarAndResults data={stateData[0]} />, document.getElementById('container'));
这是一个有效的例子。
http://jsfiddle.net/diegochavez/5q644d53/2/
最好,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.