【问题标题】:can't find method in react native component class在反应原生组件类中找不到方法
【发布时间】:2019-10-08 07:38:13
【问题描述】:

嗨,我是新来的反应本机和玩他们的方法。我已经声明了 albumCards 方法,但它在运行时给我带来了问题。

import React, { Component } from 'react';
import { Text, ScrollView, View, ActivityIndicator } from 'react-native';
import axios from 'axios';
import AlbumDetail from './albumDetail';

class AlbumList extends Component {
  state = { albums : [] };

  albumCards() {
    return this.state.albums.map(album =>
      <AlbumDetail key={album.title} album={album}/>
    );
  }

  renderAlbums() {
    if (this.state.albums.length > 0) {
      return <ScrollView> { albumCards() } </ScrollView>
    } else {
      return  <ActivityIndicator size="large" color="#0000ff" />
    }
  }

  render() {
    console.log(this.state);
    return (
      <View style = {styles.containerStyle}>
        {this.renderAlbums()}
      </View>
    );
  };
}


export default AlbumList;

我在屏幕截图中收到以下错误,因为找不到相册卡。谁能帮忙。

【问题讨论】:

    标签: ios iphone reactjs react-native


    【解决方案1】:

    你需要像这样调用函数。

    <ScrollView> { this.albumCards } </ScrollView>
    

    【讨论】:

    • 我仍然收到错误,因为必须在文本组件中呈现文本字符串
    • @AnilKothari 请同时检查 albumDetail 组件。在 React Native 中,你不能在 标签之外渲染任何文本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 2017-05-10
    • 2020-03-09
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多