慕桂英3389331
这个问题已经得到了大部分的回答,但是很多人错过了创建变量的副本。在此处查看此答案:在 React 中使用 setState 更新对象this.state ={ collections: [ { id: 1, name: 'messages', label: 'Messages', new_group: true, new_chat: true, new_friend: false, data: [ { id: 1, name: 'Patsy Paulton', status: 'Traditional heading elscas sdscsd sdcsdsc', imageUrl: 'https://via.placeholder.com/150', newMessage: true, newMessageCount: 2, avatarStatus: 'avatar-state-success' }, { id: 2, name: 'Karl Hubane', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 3, name: 'Entertainment Group', status: '<strong>Maher Ruslandi: </strong>Hello!!!', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 4, name: 'Jennica Kindred', status: 'I know how important this file is to you. You can trust me ;)', imageUrl: 'https://via.placeholder.com/150', newMessage: false, avatarStatus: 'avatar-state-warning' }, { id: 5, name: 'Marvin Rohan', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 6, name: 'Frans Hanscombe', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false } ] }, { id: 2, name: 'sms_groups', label: 'SMS Groups', new_group: false, new_chat: false, new_friend: true, data: [ { id: 1, name: 'Harrietta Souten', status: 'Traditional heading elscas sdscsd sdcsdsc', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 2, name: 'Aline McShee', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 3, name: 'Brietta Blogg', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 4, name: 'Karl Hubane', status: 'I know how important this file is to you. You can trust me ;)', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 5, name: 'Jillana Tows', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 6, name: 'Alina Derington', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 7, name: 'Stevy Kermeen', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 8, name: 'Gloriane Shimmans', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 9, name: 'Bernhard Perrett', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false } ] }, { id: 3, name: 'phone_numbers', label: 'Phone Numbers', new_group: false, new_chat: false, new_friend: false, data: [ { id: 1, name: 'Jennica Kindred', status: 'Traditional heading elscas sdscsd sdcsdsc', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 2, name: 'Marvin Rohan', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 3, name: 'Frans Hanscombe', status: 'Lorem ipsum dolor sitsdc sdcsdc sdcsdcs', imageUrl: 'https://via.placeholder.com/150', newMessage: false }, { id: 4, name: 'Karl Hubane', status: 'I know how important this file is to you. You can trust me ;)', imageUrl: 'https://via.placeholder.com/150', newMessage: false } ] } ]};// create a copy of your stateconst collections = Object.assign([], this.state.collections);// do your changescollections.forEach(cl => { if(cl.name === 'sms_groups') { // put your new data object here cl.data={}; }});//this.setState({collections});console.log(collections);<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>