我正在尝试使用127
运行React Native应用程序,但是在调试器中出现以下错误:
该应用程序依赖于我确实在react-native run-ios
上运行的Django后端。
在应用模拟器中,我看到以下错误:
这与localhost:8000
中定义的Timeline
组件有关,类似于
timeline.ui.js
-大概是由于控制台中记录的网络错误-export default class Timeline extends Component {
renderItem = ({ item, index, section }) => {
const formattedTime = formatTime(item.scheduledFor, this.props.timezone);
const TimeView = ({ text, icon, color = 'dimgrey' }) => (
<View style={styles.time}>
<Image style={[styles.timeIcon, { tintColor: color }]} source={icon} />
<Text style={[styles.timeText, { color }]}>{text}</Text>
</View>
);
let timeView;
let recommended;
switch (item.status) {
case 'Completed':
timeView = <TimeView text={`Completed: ${formattedTime}`} icon={doneIcon} />;
break;
case 'Scheduled':
timeView = <TimeView text={`Scheduled: ${formattedTime}`} icon={doneIcon} />;
break;
case 'Times Requested':
if (item.schedulingNotes.length > 0) {
timeView = <TimeView text="Reschedule Request Received" icon={pendingIcon} />;
} else {
timeView = <TimeView text={`Requested: ${item.requestedTimeframe}`} icon={pendingIcon} />;
}
break;
case 'Times Provided':
timeView = <TimeView text="Times available - please select a time" icon={pendingIcon} color={COLOR_PRIMARY} />;
break;
default:
if (item.recommended) {
recommended = (
<View style={{
flexDirection: 'row', flex: 1, alignItems: 'center', marginBottom: 5,
}}
>
<Image style={{ tintColor: COLOR_PRIMARY, height: 10, width: 10 }} source={starIcon} />
<Text style={[styles.timeText, { color: COLOR_PRIMARY }]}>Recommended</Text>
</View>
);
}
}
return (
<View style={styles.row} key={index}>
<View style={styles.details}>
<TouchableOpacity onPress={() => this.props.onSessionClicked(section.key, index)}>
<View style={styles.innerDetails}>
<View style={{ flexDirection: 'row' }}>
<View style={[styles.circle, { backgroundColor: COLORS[item.sessionType.categoryName] }]}>
<Image
style={{
height: ICON_SIZE[item.sessionType.categoryName],
width: ICON_SIZE[item.sessionType.categoryName],
tintColor: COLOR_WHITE,
}}
source={ICONS[item.sessionType.categoryName]}
/>
</View>
<View style={{ flexDirection: 'column', flex: 1 }}>
{recommended}
<Timeline.ItemTitle item={item} />
{timeView}
<Markdown>{item.sessionType.shortDescription}</Markdown>
</View>
</View>
</View>
</TouchableOpacity>
</View>
</View>
);
};
render() {
let listView;
if (this.props.error) {
listView = (
<View style={styles.error}>
<Image resizeMode={Image.resizeMode.contain} source={logoGreenIcon} />
<View style={styles.errorMessage}>
<Text style={styles.errorMessageText}>{'Apologies!\nSomething went wrong with your plan. Our team has been notified and you’ll be hearing from us soon. You can also contact us via the "Message Your Guide" button'}</Text>
</View>
</View>);
} else if (this.props.loading) {
listView = (
<View style={styles.error}>
<ActivityIndicator size="large" />
</View>);
} else {
let text = moment().format('dddd, MMM D, YYYY');
if (this.props.sessionsRemaining && this.props.sessionsTotal) {
text = `${this.props.sessionsRemaining} out of ${this.props.sessionsTotal} sessions remaining`;
}
listView = (
<View style={styles.subContainer}>
<Text style={styles.textRemaining}>{text}</Text>
{
this.props.checkIn && (
<CheckIn
key={this.props.checkIn.id}
id={this.props.checkIn.id}
title={this.props.checkIn.titleWithDefault}
onPress={() => this.props.onCheckInPress(this.props.checkIn.id)}
/>
)
}
{
this.props.feedbackRequested.map(session => (
<Feedback
key={session.id}
sessionId={session.id}
sessionName={session.sessionType.title}
expertName={session.expert ? session.expert.name : ''}
onSubmit={this.props.onFeedbackSubmit}
/>
))
}
<SectionList
refreshControl={
<RefreshControl
refreshing={this.props.refreshing}
onRefresh={() => this.props.refreshTimeline(true)}
/>
}
stickySectionHeadersEnabled
contentContainerStyle={styles.listContainer}
renderSectionHeader={this.renderSectionHeader}
renderItem={this.renderItem}
keyExtractor={(item, index) => index}
sections={this.props.timeline.map((bucket, index) => ({ data: bucket.sessions, title: bucket.title, key: index }))}
/>
</View>);
}
return (
<View style={styles.container}>
{listView}
<IntercomButton />
</View>
);
}
}
}
是item.sessionType
,导致出现了undefined
。
但是,相对于React Native来说还比较陌生,我正在努力寻找如何开始调试此问题的方法。任何想法可能是什么问题?