1

我想創建一個按鈕列表取決於數據的二維數組我做了它在角度2與嵌套ngfor但我不能做到這一點在原生反應,所以會是什麼這相當於:我想嵌套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> 

而且知道如何,因爲我要設置相關的陣列

回答

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>