将数据从子级传递到父级返回未定义的对象不是对象(评估'new _reactNative.ListView.DataSource')

时间:2020-11-11 21:03:55

标签: javascript reactjs react-native

Am试图使用以下方式将数据从一个组件(子组件)传递到另一组件(父组件)

反应本机ListView数据源

这又返回此错误public final class Comment implements com.example.barrechat192.data.entities.Comment { ^ Tried the following constructors but they failed to match: Comment(java.lang.String,com.example.barrechat192.data.entities.User,java.lang.String,long,java.lang.String) -> [param:objectId -> matched field:objectId, param:author -> matched field:unmatched, param:momentId -> matched field:momentId, param:timestamp -> matched field:timestamp, param:content -> matched field:content]C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\Comment.java:13: error: Cannot find setter for field. private final java.lang.String _author = null; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\Comment.java:17: error: Cannot find setter for field. private final java.lang.String objectId = null; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\Comment.java:23: error: Cannot find setter for field. private final long timestamp = 0L; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\DirectMessage.java:7: error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). public final class DirectMessage implements com.example.barrechat192.data.entities.DirectMessage { ^ Tried the following constructors but they failed to match: DirectMessage(java.lang.String,com.example.barrechat192.data.entities.User,com.example.barrechat192.data.entities.User,java.lang.String,long) -> [param:objectId -> matched field:objectId, param:author -> matched field:unmatched, param:recipient -> matched field:unmatched, param:content -> matched field:content, param:timestamp -> matched field:timestamp]C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\DirectMessage.java:10: error: Cannot find setter for field. private final java.lang.String _author = null; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\DirectMessage.java:13: error: Cannot find setter for field. private final java.lang.String _recipient = null; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\DirectMessage.java:17: error: Cannot find setter for field. private final java.lang.String objectId = null; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\DirectMessage.java:25: error: Cannot find setter for field. private final java.lang.String content = null; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\messages\DirectMessage.java:26: error: Cannot find setter for field. private final long timestamp = 0L; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\implementations\mapobjects\MapObject.java:10: error: The name "map_objects" is used by multiple entities or views: com.example.barrechat192.data.entities.implementations.mapobjects.MapObject, com.example.barrechat192.data.entities.implementations.mapobjects.MapObject public final class MapObject implements com.example.barrechat192.data.entities.MapObject { ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\AppDatabase.java:8: error: The name "map_objects" is used by multiple entities or views: com.example.barrechat192.data.entities.implementations.mapobjects.MapObject, com.example.barrechat192.data.entities.implementations.mapobjects.MapObject public abstract class AppDatabase extends androidx.room.RoomDatabase { ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\geocache\GeoTableWithMapObjects.java:12: error: Cannot find the child entity column `geohash` in com.example.barrechat192.data.entities.implementations.mapobjects.MapObject. Options: objectId, timestamp, thumbnailUrl, thumbnailPath, objectType, local, views, viewed, geoHash, latitude, longitude private final java.util.List<com.example.barrechat192.data.entities.implementations.mapobjects.MapObject> mapObjects = null; ^C:\Users\Anon\AndroidStudioProjects\Barrechat192\app\build\tmp\kapt3\stubs\debug\com\example\barrechat192\data\entities\geocache\GeoTableWithMapObjects.java:6: error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

这是ListItem组件(它是子组件)

undefined is not an object(evaluating 'new _reactNative.ListView.DataSource')

现在,我知道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; 函数中存在错误,因为无法使数组在onRowPress函数中起作用(这我不知道如何执行)。

与此同时,在

ViewAttendance组件(它是父组件)。

这就是我所拥有的

render

我该如何解决眼前的问题?

0 个答案:

没有答案