【发布时间】:2016-04-14 18:31:14
【问题描述】:
如果我有
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'?
}
});
【问题讨论】:
-
鉴于此代码示例,由于您没有使用模块并且代码似乎是在同一范围内编写的,因此您可以从组件中的任何函数访问
stateData。
标签: javascript object reactjs