reactjs - 在 React Native 中呈现虚拟数据时,Map 函数不起作用

标签 reactjs react-native

map 函数在 React Native 渲染数据时不起作用

const DataList = [
    {
      id: '1',
      title: 'B',
      name: 'Rulisa Andara',
      phone: '+ 62 112 3456 2311',
    },
    {
      id: '2',
      title: 'C',
      name: 'Tamara Amaris',
      phone: '+ 62 112 0984 2456',
    },

    {
      id: '3',
      title: 'D',
      name: 'Tania Sultan',
      phone: '+ 62 234 4534 3464',
    },

    {
      id: '4',
      title: 'E',
      name: 'Maria Tamani',
      phone: '+ 62 999 1123 2345',
    },
  ];
  const list = () => {
    return DataList.map(e => {
      return (
        <View style={styles.container} key={e.id}>
          <InputSearching />
          <View style={{margin: 20}}>
            <View>
              <Text>{e.title}</Text>
            </View>
            <View style={styles.wrapperList}>
              <View style={styles.wrapperImageList}>
                <Image style={styles.imageList} source={iconUser} />
              </View>
              <View>
                <Text>{e.name}</Text>
                <Text>{e.phone}</Text>
              </View>
              <View style={styles.wrapperOptionsList}>
                <Text style={styles.optionsList}>...</Text>
              </View>
            </View>
          </View>
        </View>
      );
    });
  };
  return <View>{list()}</View>;
};

最佳答案

你不需要返回

  const list = () => {
     DataList.map(e => {     
        <View style={styles.container} key={e.id}>
          <InputSearching />
          <View style={{margin: 20}}>
            <View>
              <Text>{e.title}</Text>
            </View>
            <View style={styles.wrapperList}>
              <View style={styles.wrapperImageList}>
                <Image style={styles.imageList} source={iconUser} />
              </View>
              <View>
                <Text>{e.name}</Text>
                <Text>{e.phone}</Text>
              </View>
              <View style={styles.wrapperOptionsList}>
                <Text style={styles.optionsList}>...</Text>
              </View>
            </View>
          </View>
        </View>    
    });
  };
  return <View>{list()}</View>;
};

关于reactjs - 在 React Native 中呈现虚拟数据时,Map 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71549012/

相关文章:

javascript - react + 终极版 : submit multi-component form

react-native - 由于错误 "error: uncompiled PNG file passed as argument. Must be compiled first into .flat file.."无法生成 apk

android - 无法在 Android 设备 :failed to find target with hash string 'android-23' 上构建 react-native 应用程序

react-native - 有没有办法可以忽略 React Native 中文本上的触摸事件?

javascript - 如何从动态添加的字段中获取差异 - React

android - 组合多个导航的 react 导航

reactjs - 在 Material-UI 中使用条件样式与 styled vs JSS

javascript - 分层 react View 中的状态传播

android - React-Native:错误无法安装应用程序。确保您正在运行 Android 模拟器

reactjs - 从 react 导航堆栈中删除最后一条路线