我是reactjs中的新成员,我使用reactjs创建了一个演示项目。在我的应用程序中,我在屏幕上显示数据时遇到了问题。这里是我的代码在组件间传递数据reactjs
import React, {Component} from 'react';
import $ from 'jquery';
import Users from './userlist';
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {person: []};
}
componentDidMount() {
console.log("componentDidMount")
this.UserList();
}
UserList() {
return $.getJSON('/react/getUsers')
.then((data) => {
this.setState({ person: data.data });
});
}
render() {
return (
<div>
<Users getUserData = {this.state.person}></Users>
</div>
)
}
}
Home.contextTypes = {
router: React.PropTypes.object.isRequired,
}
在此我打电话组件Users
这里是用户组件文件:
import React, {Component} from 'react';
import $ from 'jquery';
export default class Users extends Component {
render() {
console.log(this.props.getUserData)// contains array of objects which am wants to show
return(
<div className="experience-item">
<div className="experience-content experience-color-blue">
<h4>value should be here</h4>
<h6>value should be here</h6>
<p>value should be here</p>
</div>
</div>
)
}
}
什么是哟所面临的问题? –
如何循环用户组件中的数据 – Karan