我有一个代表企业营业时间的屏幕。
我按照以下方式存储我输入的小时数:
<FormLabel labelStyle={styles.formLabel}>de: </FormLabel>
<CustomInput
underlineColorAndroid="#58CAF1"
style={styles.inputScheduleTime}
// ref="lundiStart"
placeholder="8H00..."
keyboardType="numeric"
onBlur={ input => {
let input1 = input.nativeEvent.text;
this.setState({ monday: {
start: input1 ,
end: "",
selected: this.state.monday.selected
}
});
}
}
/>
<CustomInput
underlineColorAndroid="#58CAF1"
style={styles.inputScheduleTime}
// ref="lundiStart"
placeholder="8H00..."
keyboardType="numeric"
onBlur={ input => {
let input2 = input.nativeEvent.text;
this.setState({ monday: {
start:this.state.monday.start + ':' + input2,
end: "",
selected: this.state.monday.selected
}
});
}
}
/> ...
然后在第二个屏幕上,我填写一个对象来更新我在firebase上的数据:
if (this.state.monday.selected == true) {
this.user.monday = this.state.monday;
console.log(this.state.monday)
} ...
当我想读你的数据时。另一个屏幕我按如下方式进行:
}).then((userData) => {
//Schedule :
if (userData.monday.start !== "" || userData.monday.end !== "" && userData.monday.selected == true) {
this.setState({
schedule : {Lundi: userData.monday},
// days: ['Lundi']
});
} else {
this.setState({
schedule : { },
// days: [" "]
});
} ...
然后我有一个显示我的日程安排的功能:
renderScheduleDay(){
return Object.keys(this.state.schedule)
.map((schedule, key) => (
<View key={key} style={styles.containerSchedule}>
<CheckBox
title={schedule}
containerStyle={styles.containerStyle}
checked
/>
<Text>
{this.state.schedule[schedule]['start'] !== null || this.state.schedule[schedule]['end'] !== null ?`Ouvert de ${this.state.schedule[schedule]['start']} h à ${this.state.schedule[schedule]['end']} h` : 'fermé !'}
</Text>
</View>
));
}
我想只显示数据出现和/或更新的日期,但我有这样的错误:&#34;无法读取属性&#39;启动&#39;未定义&#34; ??
也许我设置状态的方式? 还是我的数据渲染条件?