我正在尝试将一个元素数组传递给列表视图,然后在我的comp
中呈现它们数据源
listenForItems(itemsRef) {
itemsRef.on('value', (snap) => {
// get children as an array
var items = [];
snap.forEach((child) => {
items.push({
date: child.val().date,
name: child.val().name,
email: child.val().email,
phone: child.val().phone,
notes: child.val().notes,
items: child.val().items,
_key: child.key
});
});
this.setState({
dataSource: this.state.dataSource.cloneWithRows(items)
});
});
}
组件
render () {
return (
<View style={styles.container}>
<View style={styles.orderDetail}>
<View style={styles.buttons}>
<Text style={styles.name}>{this.props.item.name}</Text>
<Text style={styles.item}>{this.props.item.items.name}</Text>
<Text style={styles.price}>{this.props.item.items.price}</Text>
</View>
<Text style={styles.notes}>NOTES</Text>
<Text style={styles.note}>{this.props.item.notes}</Text>
</View>
<View style={styles.buttons}>
<TouchableOpacity style={styles.rejectButton} onPress={ this._rejectOrder }>
<Text style={styles.buttonText}>REJECT</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.acceptButton} onPress={ this._acceptOrder }>
<Text style={styles.buttonText}>ACCEPT</Text>
</TouchableOpacity>
</View>
</View>
)
答案 0 :(得分:1)
看起来你的<Text>
元素之一包含的不仅仅是字符串。
我打赌:<Text style={styles.note}>{this.props.item.notes}</Text>
您需要确保this.props.item.notes
是字符串而不是对象