我正在尝试访问子组件中的 props,我正在使用映射的 json 结果渲染网格行:
getRowNodes: function() {
return this.props.contacts.map(function(contact){
return <Row
key={contact.id}
contact={contact}
columns={this.props.children} />;
}.bind(this));
}
当我渲染组件时,我可以控制台日志 {this.props.data} 并查看所有属性,我还可以在 chrome 开发工具中查看所有属性,但是,当我尝试访问属性 this.props 时。 data.propertyName 我未定义。
如果我尝试访问下面的任何属性,我会收到错误......有什么想法吗?
最佳答案
就像Kirill Slatin所说:你必须把它包起来。
试试这个:
getRowNodes() {
return (
<div>
{this.props.contacts.map(this._getRow)}
</div>
);
},
_getRow(contact) {
return (
<Row
key={contact.id}
contact={contact}
columns={this.props.children} />
);
}
NOTE: I have optimized the readability by using JSX Syntax.
关于javascript - ReactJs 无法访问 props,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31132170/