【发布时间】:2018-07-03 12:30:42
【问题描述】:
我有这个变量
const routes = [{data : 'Home' , icon : 'home' , keep:true , txt:'Home'} , {data : 'NECard' , icon : 'card' , keep:true , txt:'Your Card'} , {data : 'Notifications' , icon : 'notifications' , color : '#EB4D4B' , count : 27 , keep:true , txt:'Notifications'} , {data : 'Requests' , icon : 'contacts' , color : '#0097E6' , count : 8 , keep:true , txt:'Requests'} , {data : 'Saved' , icon : 'bookmark' , color : '#FBC531' , count : 51 , keep:true , txt:'Saved'} , {data : 'Logout' , icon : 'ios-exit' , keep:true , txt:'Logout'}];
我在构造函数中设置状态
this.state = {routes : routes};
在安装组件后我运行它
componentDidMount()
{
this.fetchNotReadedNotis();
}
最后一步
async fetchNotReadedNotis()
{
this.state.routes[2].count = 392;
this.forceUpdate();
}
使用 setState 也不起作用
async fetchNotReadedNotis()
{
var rts = this.state.routes;
rts[2].count = 392;
this.setState({routes:rts});
}
预期将 routes[2] 计数属性设置为 392
但完全没有变化,还是 27
我的代码有问题吗?
【问题讨论】:
标签: javascript reactjs react-native