showAllPics(docid){

        console.log(docid)
        var newSelected = Object.assign({},this.state.CompetitorPhotos);

        console.log("b4-->",newSelected[docid]['display']);
        newSelected[docid]['display'] = true;
        console.log("after -->",newSelected[docid]['display'],newSelected);

        console.log(newSelected,this.state.CompetitorPhotos)

        this.setState({ CompetitorPhotos: newSelected },function(){
            console.log(newSelected,this.state.CompetitorPhotos)
        });

    }


我正在尝试在reactjs状态的嵌套属性中更新'display'属性。
以下代码失败...我在做什么错..

    console.log("after -->",newSelected[docid]['display'],newSelected);
    results in "after -->",true, newSelected.docid.display remains false

最佳答案

您可以使用...更新嵌套状态
只要看一下这个问题:react set state in for nested state

return {
    ...state,
    fetching: false,
    fetched: true
}

10-06 04:30