以下是存储在this.state.activeEvents
中用于响应本机应用程序的节列表数据数组:
[ { title: '2019-04-10',
data:
[ { id: 2,
name: 'test event2',
event_info: { end_datetime: '2019-04-10' },
current_step: 'step2',
customer_id: 1,
access_list: null,
event_snapshot: null,
event_category_id: null,
status: 'active',
last_updated_by_id: null,
createdAt: '2019-03-22T07:00:00.000Z',
updatedAt: '2019-03-22T07:00:00.000Z' } ] },
{ title: '2019-04-12',
data:
[ { id: 1,
name: 'test event1',
event_info: { end_datetime: '2019-04-12' },
current_step: 'step1',
customer_id: 1,
access_list: null,
event_snapshot: null,
event_category_id: null,
status: 'active',
last_updated_by_id: null,
createdAt: '2019-03-24T07:00:00.000Z',
updatedAt: '2019-03-24T07:00:00.000Z' } ] } ]
这里是render()
:
return (
<View style={styles.container}>
<SectionList
sections={this.state.activeEvents}
renderItem={({item, index, section}) => <Text style={styles.item} key={item.data.id}>{item.name}</Text>}
renderSectionHeader={({section}) => <Text style={styles.sectionHeader}>{section.title}</Text>}
keyExtractor={(item, index) => index}
/>
</View>
);
渲染器出现错误:
03-28 11:54:39.539 11934 11999 E ReactNativeJS: TypeError: TypeError: undefined is not an object (evaluating 'section.data.length')
-28 11:54:39.539 11934 11999 E ReactNativeJS: This error is located at:
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in VirtualizedSectionList (at SectionList.js:332)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in SectionList (at Event.js:108)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at Event.js:107)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in Event (created by SceneView)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in SceneView (at StackViewLayout.js:784)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at StackViewLayout.js:783)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at StackViewLayout.js:782)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at createAnimatedComponent.js:151)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in AnimatedComponent (at StackViewCard.js:69)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at createAnimatedComponent.js:151)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in AnimatedComponent (at screens.native.js:59)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in Screen (at StackViewCard.js:57)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in Card (at createPointerEventsContainer.js:27)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in Container (at StackViewLayout.js:860)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at screens.native.js:83)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in ScreenContainer (at StackViewLayout.js:311)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at createAnimatedComponent.js:151)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in AnimatedComponent (at StackViewLayout.js:307)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in PanGestureHandler (at StackViewLayout.js:300)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in StackViewLayout (at withOrientation.js:30)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in withOrientation (at StackView.js:79)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at Transitioner.js:214)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in Transitioner (at StackView.js:22)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in StackView (created by Navigator)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in Navigator (at createKeyboardAwareNavigator.js:12)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in KeyboardAwareNavigator (at createAppContainer.js:388)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in NavigationContainer (at renderApplication.js:35)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at AppContainer.js:98)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at AppContainer.js:115)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in AppContainer (at renderApplication.js:34)
03-28 11:54:39.539 11934 11999 E ReactNativeJS:
03-28 11:54:39.539 11934 11999 E ReactNativeJS: This error is located at:
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in NavigationContainer (at renderApplication.js:35)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at AppContainer.js:98)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in RCTView (at View.js:45)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in View (at AppContainer.js:115)
03-28 11:54:39.539 11934 11999 E ReactNativeJS: in AppContainer (at renderApplication.js:34)
问题肯定出在这行上,但我不知道它在哪里:
renderItem={({item, index, section}) => <Text style={styles.item} key={item.data.id}>{item.name}</Text>}