包含元素数组的列表视图

list view with array of elements

我正在尝试将元素数组传递给列表视图,然后在我的组件中呈现它们

数据源

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>
    )

看起来您的 <Text> 元素之一包含的不仅仅是字符串。

我会打赌:<Text style={styles.note}>{this.props.item.notes}</Text>

您需要确保 this.props.item.notes 是字符串而不是对象