Javascript 将数据从子级传递到父级返回未定义的对象不是对象(正在计算';新reactNative.ListView.DataSource';)
我试图使用以下命令将数据从一个组件(子组件)传递到另一个组件(父组件) 反应本机ListView数据源 然后返回此错误Javascript 将数据从子级传递到父级返回未定义的对象不是对象(正在计算';新reactNative.ListView.DataSource';),javascript,reactjs,react-native,Javascript,Reactjs,React Native,我试图使用以下命令将数据从一个组件(子组件)传递到另一个组件(父组件) 反应本机ListView数据源 然后返回此错误undefined不是对象(评估'new\u reactNative.ListView.DataSource') 这是ListItem组件(它是子组件) 我如何解决手头的问题 import React, { Component } from 'react'; import { Text, TouchableWithoutFeedback } from 'react-native'
undefined不是对象(评估'new\u reactNative.ListView.DataSource')
这是ListItem组件(它是子组件)
我如何解决手头的问题
import React, { Component } from 'react';
import { Text, TouchableWithoutFeedback } from 'react-native';
import { Icon, Container } from 'native-base';
import moment from 'moment';
class ListItem extends Component {
constructor(){
super();
this.state = {
attendance: []
};
}
attendee = [{
courseName: 'comp',
lecturer: 'Akanbi T.B',
students: 'Tunde Ajagba',
date: '10/11/2020',
},{
courseName: 'comp',
lecturer: 'Akanbi T.B',
students: 'Tunde Ajagba',
date: '09/11/2020',
},
{
courseName: 'comp',
lecturer: 'Akanbi T.B',
students: 'Tunde Ajagba',
date: '08/11/2020',
},
{
courseName: 'comp',
lecturer: 'Akanbi T.B',
students: 'Kola Babatunde',
date: '09/11/2020',
},
{
courseName: 'comp',
lecturer: 'Akanbi T.B',
students: 'Kola Babatunde',
date: '10/11/2020',
}
];
onRowPress() {
this.record = this.attendee.map(function(item,index) {
alert("item: " + item.courseName + " at index: " + index );
});
//const { navigate } = this.props.navigation;
//navigate('attendanceDetails', { record });
}
render() {
return (
<TouchableWithoutFeedback onPress={this.onRowPress.bind(this)}>
<Container style={styles.containerStyle}>
<Text style={styles.labelStyle}>Course:</Text>
<Text style={styles.titleStyle}>{courseName}</Text>
<Text style={styles.labelStyle}>Date:</Text>
<Text style={styles.titleStyle}>
</Text>
<form onSubmit = {this.onTrigger}>
<input type = "submit" value = "Submit"/>
</form>
<Icon name='ios-arrow-forward' style={{ color: 'grey', marginLeft: 5 }} />
</Container>
</TouchableWithoutFeedback>
);
}
}
export default ListItem;
import _ from 'lodash';
import React, { Component } from 'react';
import { ListView, ScrollView } from 'react-native';
import { Container } from 'native-base';
import AsyncStorage from '@react-native-community/async-storage';
import ListItem from './ListItem';
export default class ViewAttendance extends Component {
constructor(props){
super(props);
}
componentWillMount() {
const { lecturer } = "Akanbi T.B";//this.props.route.params;
this.createDataSource(this.props);
}
componentWillReceiveProps(nextProps) {
this.createDataSource(nextProps);
}
createDataSource({ records }) {
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
const items = _.map(records, (val, key) => {
return { ...val, key };
});
this.dataSource = ds.cloneWithRows(items);
}
renderRow(record, navigation) {
return (
<ListItem record={record} navigation={navigation} />
);
}
render() {
const { navigation } = 'a';//this.props.route.params;
return (
<Container style={styles.containerStyle}>
<ListView
enableEmptySections
dataSource={this.dataSource}
renderRow={(record) => this.renderRow(record, navigation)}
/>
</Container>
);
}
}
};