我从本地json中提取数据并通过列表显示它,每次我退出应用程序而不杀死它或断开连接并重新连接数据都是重复的(回想一下解析方法)我的代码看起来像这样 如果我重新加载或杀死应用程序并重新打开它,我将得到正常的数据
class Overview extends Component {
constructor(props, context) {
super(props, context);
this.state = {
Type: [],
Nom: [],
Planning: [],
Name: [],
FrostFreeTemperature: [],
}
}
ParseHouse = () => {
for (var i = 0; i < rooms.length; i++) {
var obj_room = rooms[i];
this.state.Name.push(obj_room.Name);
this.state.Planning.push(obj_room.Planning);
for (var j = 0; j < this.state.Planning.length; j++) {
try {
var obj_plan = this.state.Planning[i][j]
this.state.Type.push(obj_plan.Type);
if (this.state.Type[i].toUpperCase() == "ABSENCE") {
nbr_room_Absence++;
RoomsAbsence.push(this.state.Name[i]);
} else if (this.state.Type[i].toUpperCase() == "COMFORT") {
nbr_room_Comfort++;
RoomsComfort.push(this.state.Name[i]);
} else if (this.state.Type[i].toUpperCase() == "FROST FREE") {
nbr_room_FrostFree++;
RoomsFrostFree.push(this.state.Name[i]);
}
} catch (err) {
}
}
}
}
componentWillMount(){
this.ParseHouse();
}
_renderContentAbsence() {
return (
<View>
<List
dataArray={RoomsAbsence}
renderRow={(roomAb) =>
<ListItem>
<Text>{roomAb}</Text>
</ListItem>
}>
</List>
</View>
);
}
render(){
return(
<ScrollView style={styles.scroll}>
<Navbar/>
<StatusBar
backgroundColor="#1769AC"
barStyle="light-content"
/>
<Accordion
sections={Absence}
renderHeader={this._renderHeaderAbsence}
renderContent={this._renderContentAbsence}>
</Accordion>
</ScrollView>
);
}
}
有没有解决方案,谢谢