列表视图与元素数组

时间:2017-02-27 09:13:23

标签: listview firebase react-native components listviewitem

我正在尝试将一个元素数组传递给列表视图,然后在我的comp

中呈现它们

enter image description here

数据源

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

1 个答案:

答案 0 :(得分:1)

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

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

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