【发布时间】:2019-05-16 06:48:50
【问题描述】:
无法显示在 Eventform 中输入的文本并显示在 EventList 页面的平面列表中。我是 react native 的新手,需要一些帮助来解决问题。学习开发笔记应用程序。
EventForm js 我在其中输入了具有名称位置和注释字段的文本,但是当按下添加按钮时,它不会在平面列表中显示。
class EventForm extends Component {
state = {
title: null,
date: '',
};
handleAddPress = () => {
saveevents(this.state)
// console.log('saving events:', this.state);
.then(()=> this.props.navigation.goBack());
}
// handlePress() {
// this.props.onBtnPress()
// }
// }
handleChangeTitle = (text) => {
this.setState({ title: text });
}
handleChangeLocation =(text) => {
this.setState({location: text});
}
render() {
return (
<View
style={{
flex: 1
}}
>
<View style={styles.fieldContainer}>
<TextInput
style={styles.text}
placeholder="Name"
spellCheck={false}
value={this.state.title}
onChangeText={this.handleChangeTitle}
/>
<TextInput
style={styles.text}
placeholder="Enter your Location"
spellCheck={false}
value={this.state.location}
onChangeText={this.handleChangeLocation}
/>
<AutoExpandingTextInput
placeholder="Write your Notes here"
spellCheck={false}
style={[styles.default, {height: Math.max(35, this.state.height)}]}
value={this.state.text}
/>
</View>
<TouchableHighlight
onPress ={() =>this.handleAddPress.bind(this)}
// onPress={this.handleAddPress}
style={styles.button}
>
<Text style={styles.buttonText}>Add</Text>
</TouchableHighlight>
</View>
我想显示在 EventForm 中输入的动态文本的 EventList js 应该出现在 flatlist 中。我将平面列表内容保存在 db json 文件中并在 EventList 中调用它。
const styles = StyleSheet.create({
list: {
flex: 1,
paddingTop: 20,
backgroundColor: '#A9A9A9'
},
});
class EventList extends Component {
state = {
events: [],
}
componentDidMount() {
//getEvents().then(events => this.setState({ events }));
const events = require('./db.json').events;
this.setState({ events });
}
render() {
return [
<FlatList
key="flatlist"
style={styles.list}
data={this.state.events}
renderItem={({ item, seperators }) => (<EventCard events=
{item} />)}
keyExtractor={(item, index) => index.toString()}
/>,
我的 db json 文件是我手动输入的详细信息。动态输入的数据必须保存在 db json 文件中,并且应该反映在 flatlist 中。
{
"events":[
{
"name":"chandu",
"date":"15-06-2018 ",
"location":"Sydney",
"content":"How are you..?",
"id":"05dafc66-bd91-43a0-a752-4dc40f039144"
},
{
"name":"bread",
"date":"15-07-2018 ",
"location":"Sydney",
"content":"I bought bread..?",
"id":"05dafc66-bd91-43a0-a752-4dc40f039145"
}
]
}
我希望在表单中输入的任何文本都应该保存并显示在 EventList 文件中的 Flatlist 上。如果您有任何解决方案,请提供帮助。
我在 onPressed 时添加了警报消息以显示它是否被按下。
我希望在表单中输入的任何文本都应该保存并显示在 EventList 文件中的 Flatlist 上。如果您有任何解决方案,请提供帮助。 我在 onPressed 时添加了警报消息以显示它是否被按下。
【问题讨论】:
标签: react-native react-native-android react-native-flatlist react-native-navigation