【问题标题】:How to add view dynamically with state in ReactNative如何在 React Native 中动态添加带有状态的视图
【发布时间】:2018-02-28 23:10:23
【问题描述】:

我正在使用 react-native-popup-menu。代码如下:

      <Menu>
         <MenuTrigger text='Select action' />
         <MenuOptions>
           <MenuOption onSelect={() => alert(`Save`)} text='Save' />
           <MenuOption onSelect={() => alert(`Not called`)} disabled={true} text='Disabled' />
        </MenuOptions>
      </Menu>

我想从我所在州的数组中动态添加 MenuOption。我该怎么办?

【问题讨论】:

    标签: react-native jsx


    【解决方案1】:

    使用 array.map()

    {this.state.menuOptions.map(menuOption => <MenuOption onSelect={() => alert(`Save`)} text='Save' />)}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多