【问题标题】:nested ngfor equivalent in react nativereact native 中的嵌套 ngfor 等效项
【发布时间】:2017-11-19 20:27:35
【问题描述】:

我正在尝试根据二维数据数组创建一个按钮列表,我在角度 2 中使用嵌套的 ngfor 执行此操作,但我无法在本机反应中执行此操作,所以这相当于:

<table >
    <tr *ngFor="let tile of tiles; let i = index ">
        <td *ngFor="let button of tile; let j = index">
          <button type="button" (click)="click(i,j,$event.target)"class="btn-group-lg"> X</button>
        </td>
    </tr>
</table>

我也想知道如何使用索引,因为我必须为与数组相关的按钮索引设置一个操作

【问题讨论】:

    标签: javascript angular reactjs multidimensional-array react-native


    【解决方案1】:

    我是徒手写的,但它至少应该让你朝着正确的方向前进(我假设瓷砖是一种道具,如果不改变它的来源的话)。

    <table >
      {this.props.tiles.map((tile, i) => (
        <tr>
          {tile.map((button, j) => (
            <td>
              <button type="button" onClick={(event) => click(i,j,event.target)} class="btn-group-lg"> X</button>
            </td>
          ))}
        </tr>
      ))}
    </table>
    

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      相关资源
      最近更新 更多