【问题标题】:Not able to add component dynamically to view in React Native无法动态添加组件以在 React Native 中查看
【发布时间】:2015-11-21 13:53:36
【问题描述】:

我需要对api进行HTTP调用,根据返回的数据,我需要动态渲染图像。我可以在渲染函数中添加for循环并实现这一点。 问候 赫格德

【问题讨论】:

    标签: react-native


    【解决方案1】:

    虽然您可以使用 for 循环,但改用 map 会更简洁、更实用。

    render: function() {
      var images = ['a.png', 'b.png', ...];
      return (
        <View>
          {images.map((source, i) => (<Image key={i} source={source} />))}
        </View>
      );
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 2020-09-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多