首先我有一个多层对象,类似于var a = { b:{ c:{ d:"" } } } 如果我想要将a作为一个state请问应该如何初始化以下是我的尝试class App extends React.Component { constructor(props) { super(props); this.state = { data:{} }; } componentDidMount() { this.setState({data:a.b.c}); } render(){ return( <p>{this.state.d}</p> ) } } 或者是class App extends React.Component { constructor(props) { super(props); this.state = { data:"" }; } componentDidMount() { this.setState({data:a.b.c.d}); } render(){ return( <p>{this.state}</p> ) } }也就是说只能将state初始化成c和d。所以想要请教一下如何初始化成a那种形式。并且如何在里面定义数组呢,比方说b是一个含有4个元素的数组
添加回答
举报
0/150
提交
取消
