Html 使用Angulardart中的嵌套列表创建表

Html 使用Angulardart中的嵌套列表创建表,html,dart,angular-dart,Html,Dart,Angular Dart,我试图用Angulardart构建一个表示列表的表 这是我的模板文件的内容: <table> <tbody> <tr *ngFor="#row of cells"> <td *ngFor="#cell of row"> <input type="number" #cell (keyup)="0"/> </td>

我试图用Angulardart构建一个表示列表的表

这是我的模板文件的内容:

<table>
    <tbody>
        <tr *ngFor="#row of cells">
            <td *ngFor="#cell of row">
                <input type="number" #cell (keyup)="0"/>
            </td>
        </tr>
    </tbody>
</table>
列表初始化如下:

class Grid {
    const GRID_SIZE = 9;
    List<List<int>> cells = new List(GRID_SIZE);

    Grid() {
        cells.forEach((x) => x = new List(GRID_SIZE));
    }
}
然而,在呈现的HTML中,我只看到9个空标签,里面没有s


我遗漏了什么?

发现问题在于网格初始化:正确的初始化代码是

cells.fillRange(0, cells.length, new List.filled(GRID_SIZE, 0));

问题中的初始化代码只在主列表中填充了网格大小的空值。

结果表明问题出在网格初始化中:用零列表填充主列表的正确初始化代码是

cells.fillRange(0, cells.length, new List.filled(GRID_SIZE, 0));

问题中的初始化代码只在主列表中填充了网格大小的空值。

当您调用此行时:

cells.forEach((x) => x = new List(GRID_SIZE));
实际上,您正在用一个新值替换x:您没有干预x内部,而是创建了一个新值

List<String> myList = ['my', 'original', 'list'];

void yourForLoopFunctionSimulation( List<String> x ) {
  x = new List.filled(GRID_SIZE, 0);
  //you can work with the new x value here, but it won't change the argument that was passed to you
}

//if you run 
yourForLoopFunctionSimulation( myList );
print( myList ); // result : ['my', 'original', 'list'];

当你打这个电话时:

cells.forEach((x) => x = new List(GRID_SIZE));
实际上,您正在用一个新值替换x:您没有干预x内部,而是创建了一个新值

List<String> myList = ['my', 'original', 'list'];

void yourForLoopFunctionSimulation( List<String> x ) {
  x = new List.filled(GRID_SIZE, 0);
  //you can work with the new x value here, but it won't change the argument that was passed to you
}

//if you run 
yourForLoopFunctionSimulation( myList );
print( myList ); // result : ['my', 'original', 'list'];