我的文档如下:
{
first_name:"A",
last_name:"B",
subjects:
{
literature:"Eng",
science:"Physics",
//How can i add field here e.g., socialStudies:"History"
}
}
这里,主题不是任何数组。其子文档中我想添加一个新字段。请帮忙
答案 0 :(得分:1)
您可以使用点表示法进行简单设置。
class ProductPage extends Component {
constructor() {
super();
this.peekClick = this.peekClick.bind(this);
this.peekHide = this.peekHide.bind(this);
this.state = {
peekaboo: false
};
}
peekClick = () => {
this.setState({peekaboo: true});}
peekHide = () => {
this.setState({peekaboo: false});}
render() {
return (
<div className="ProductPage">
<div className="ProductPage-Left">
{/* PROBLEM IS HERE */}
<div className="leftViewTab" onBlur={this.peekHide}>
{this.state.peekaboo ? (null) :
(<div className="leftViewText" onClick={this.peekClick}>
View Store
</div>)}
</div>
</div>