【发布时间】:2018-03-02 06:25:16
【问题描述】:
这里是代码,为什么我的地图函数不返回 div 中的项目。 我在状态函数中使用了对象数组。 这是我的简单代码。 我在 componentwiillrecieveprops 中有 XML 数据。 componentwillmount 是否有任何问题。我不明白为什么 map 函数在映射我的状态数组。
import React from 'react';
import TextField from 'material-ui/TextField';
var self;
export default class NewAuthoring extends React.Component {
constructor(props) {
super(props);
self = this;
this.state = {
sampleState : "OriginalState",
task : [
{event:"First data",eventpara:"First Data"},
{event:"Second data",eventpara:"Second Data"},
{event:"Third data",eventpara:"Third Data"}
]
}
}
componentWillReceiveProps(nextProps) {
console.log(nextProps.xml)
if(this.props != nextProps) {
//Do Something when any props recieve
this.setState({sampleState:nextProps.xml});
}
}
componentWillMount() {
//Do something before component renders
let xml ="<div type=”timeline/slideshow”><section><header></header><article></article></section><section><header></header><article></article></section><section><header></header><article></article></section><section><header></header><article></article></section></div>";
self.props.getChildXml(xml);
}
componentDidMount() {
//Do Something when component is mounted
}
handleChange(e) {
//getChildXml function will update the xml with the given
//parameter and will also change the xml dialog value
let xml ="<div type=”timeline/slideshow”><section><header></header><article></article></section><section><header></header><article></article></section><section><header></header><article></article></section><section><header></header><article></article></section></div>";
self.props.getChildXml(xml);
}
render() {
const myStyle = {
mainBlock:{
fontWeight:"bold",
margin:"2px"
}
}
const div_style = {
border:'1px solid black',
margin:10
}
{
this.state.task.map((item,contentIndex) => {
return (<div>
hello
{item.event}
{item.eventpara}
</div>)
})
}
}
}
我们将不胜感激。
【问题讨论】:
标签: javascript reactjs