【发布时间】:2017-05-28 15:54:21
【问题描述】:
class CyInfo extends Component {
foo(){
console.log(this.props.id);
return getAttributes(this.props.id)
}
render() {
return ( <Info data = {this.foo()}> </Info>)
}
}
此父级接收“props.id”并将数据值传递给 getAttributes() 返回的子级。
export default class Info extends Component {
constructor(props){
super(props)
}
/*componentWillReceiveProps(nextProps){
console.log(nextProps);
*/
render() {
console.log(this.props.data);
return (
<div id="info">{this.props.data}</div>
)
}
}
在孩子身上,我可以在控制台和 componentWillReceiveProps 中看到 props 值。但数组未呈现。 我尝试使用 react-devtool。在 react-devtool 中,道具似乎通过了孩子但没有渲染。有趣的是,当我更改数组的某些元素时,react-devtool 正在渲染。
我做错了什么。
编辑: [React-Devtool 截图][1]
我编辑了 react-devtool 截图。道具似乎但组件仅呈现初始值。在屏幕截图控制台错误是 favicon 只是忽略此
【问题讨论】:
-
您在控制台上看到任何错误/警告吗?传递的数据是什么?它是一个数组..什么样的数组..你想显示什么?
-
试试
{JSON.stringify(this.props.data)}。它可能不显示的原因是它不是文本,而是一个 JavaScript 对象。 -
我用 react-devtool 和控制台截图编辑了这个问题
标签: javascript reactjs react-jsx