在Angulardart中创建具有嵌套列表的表

时间:2017-04-06 21:01:51

标签: html dart angular-dart

我试图在Angulardart中构建一个代表List<List<int>>的表。

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

<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个<tr>个空标记,里面没有<td>

我错过了什么?

2 个答案:

答案 0 :(得分:5)

原来问题出现在网格初始化中:正确的初始化代码是否填充了零列表

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

问题中的初始化代码仅使用GRID_SIZE空值填充主列表。

答案 1 :(得分:0)

当你拨打这一行时:

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'];

您实际上是用新值替换x:您没有介入x内部,但是您创建了一个新值。

if (Shared.InspectionData.JobViewModel.RAMS_Id == null || Shared.InspectionData.JobViewModel.RAMS_Id.equals("")) {
        // Disable foreground view here

        LoadRAMSPopup();
}



private void LoadRAMSPopup() {
    mainLayout.getForeground().setAlpha(150);
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);

    final View ramsView = layoutInflater.inflate(R.layout.popup_rams, null);
    final PopupWindow popupRAMS = new PopupWindow(
            ramsView,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
    );

    if (Build.VERSION.SDK_INT >= 21) {
        popupRAMS.setElevation(5.0f);
    }

    findViewById(R.id.mainLayout).post(new Runnable() {
        @Override
        public void run() {
            popupRAMS.showAtLocation(findViewById(R.id.mainLayout), Gravity.CENTER, 0, 0);
            popupRAMS.setOutsideTouchable(false);
            popupRAMS.update();

            Button btnGenerate = (Button) ramsView.findViewById(R.id.btnGenerate);
            btnGenerate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Intent intent = new Intent(getApplicationContext(), CreateRAMSActivity.class);
                    startActivity(intent);
                    popupRAMS.dismiss();
                    mainLayout.getForeground().setAlpha(0);
                }
            });
        }
    });
}