【发布时间】:2018-08-01 15:16:36
【问题描述】:
讨论应用出现问题。我只能在给定时间渲染标题或帖子。无法在 thread.jsx 中渲染。 这个应用程序在 react 和 firebase 中。 请建议我如何解决这个问题。 我认为 post 中的 map 函数不对。如何使用 map 函数编写对象。我需要把对象写成道具吗?
thread.jsx--------
postEditor.jsx-----
import React, {Component} from 'react';
import './DpostEditor.css';
export default class PostEditor extends Component {
constructor(props) {
super(props);
this.state= {
newPostBody:'',
newHeaderBody:'',
};
this. handlePostHeaderInputChange=this.handlePostHeaderInputChange.bind(this);
this.handlePostEditorInputChange = this.handlePostEditorInputChange.bind(this);
this.createPost = this.createPost.bind(this);
}
handlePostEditorInputChange(e) {
this.setState({
newPostBody : e.target.value,
})
}
handlePostHeaderInputChange(e) {
this.setState({
newHeaderBody : e.target.value,
})
}
createPost() {
this.props.addPost(this.state.newPostBody);
this.setState({
newPostBody: '',
newHeaderBody:'',
});
}
render() {
return(
<div className= "panel panel-default post-editor">
<div className="panel-body">
<textarea className= "form-control post-header-input" value={this.state.newHeaderBody} onChange={this. handlePostHeaderInputChange }/>
<textarea className= "form-control post-editor-input" value={this.state.newPostBody} onChange={this.handlePostEditorInputChange }/>
<button className= "btn btn-success post-editor-button" onClick= {this.createPost}> Post </button>
</div>
</div>
)
}
}
Post.jsx------
import React from 'react';
import './Dpost.css';
const Post= (props)=> (
<div className=" panel panel-default post-body">
<div className="panel-heading">
{props.postBody.map((header,postType,idx)=>(
<div>
<div> {header} </div>
<div> {postType} </div>
</div>
))
}
</div>
</div>
);
export default Post;
【问题讨论】:
-
您是否看到任何错误/输出?这看起来不对
onChange={this. handlePostHeaderInputChange },应该没有空格
标签: reactjs function firebase dictionary object